常用正则表达式

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

import java.util.regex.Pattern;

 

import javax.swing.JOptionPane;

 

public class HelloWorld {

public static void main(String[] args) throws IOException {

while (true) {

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

String str = br.readLine();

 

System.out.println(IPVerify(str));

}

}

 

public static boolean isDouble(String str) {

Pattern pattern = Pattern.compile("^\\d+(\\.\\d+)?$");

boolean bool = pattern.matcher(str).matches();

System.out.println("compiled: " + str);

return bool;

}

 

public static boolean dateVerify(String str) {

boolean isData = false;

final String date_regexp = "^((\\d{2}(([02468][048])|([13579][26]))[\\-\\/\\s]?"

+ "((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|"

+ "(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?"

+ "((0?[1-9])|([1-2][0-9])))))|(\\d{2}(([02468][1235679])|([13579][01345789]))"

+ "[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))"

+ "|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?"

+ "((0?[1-9])|(1[0-9])|(2[0-8]))))))";// 匹配日期

Pattern pattern = Pattern.compile(date_regexp);

isData = pattern.matcher(str).matches();

return isData;

}

 

public static boolean intVerify(String str) {

boolean isInt = false;

final String non_negative_integers_regexp = "^\\d+$";

Pattern pattern = Pattern.compile(non_negative_integers_regexp);

isInt = pattern.matcher(str).matches();

return isInt;

}

 

public static boolean timeVerify(String str) {

boolean isTime = false;

final String time_regexp = "^((0?[0-9])|([1-2][0-3]))\\:([0-5]?[0-9])((\\s)|(\\:([0-5]?[0-9])))?$";

Pattern pattern = Pattern.compile(time_regexp);

isTime = pattern.matcher(str).matches();

return isTime;

}

public static boolean IPVerify(String str) {

boolean isTime = false;

final String time_regexp = "^([1-9]|[1-9]\\d|1\\d{2}|2[0-1]\\d|22[0-3])(\\.(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])){3}$";

Pattern pattern = Pattern.compile(time_regexp);

isTime = pattern.matcher(str).matches();

return isTime;

}

 

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值