Java正则表达式
public static void main(String[] args) { String string = "0123456789"; //Pattern.compile("[0-9]+")验证的正则表达式 // .matcher(string),返回Matcher对象 // .matches(),执行验证 if (Pattern.compile("[0-9]+").matcher(string).matches()) { System.out.println("都是数字"); }else { System.out.println("不全是数字"); } }
public static void main(String[] args) { String calendar="1908-09-01"; // \\d等于[0-9],都表示数字 Pattern pattern = Pattern.compile("\\d{4}-[0-9]{2}-\\d{2}"); //返回Matcher对象 Matcher matcher = pattern.matcher(calendar); //验证 if (matcher.matches()) { System.out.println("caledar"); }else { System.out.println("no caledar"); } }
相关推荐
wangzhaotongalex 2020-10-20
wyq 2020-11-11
TLROJE 2020-10-26
风雨断肠人 2020-10-13
duanqingfeng 2020-09-29
rechanel 2020-11-16
cshanzhizi 2020-10-16
luofuIT成长记录 2020-09-22
phphub 2020-09-10
taomengxing 2020-09-07
MaggieRose 2020-08-19
flyingssky 2020-08-18
山水沐光 2020-08-18
jyj00 2020-08-15
AHuqihua 2020-08-09
山水沐光 2020-08-03