Pattern与Matcher的具体用法

这是正则表达式Pattern.compile(“a*b”);这个是规范;
Matcher m = p.matcher(“aabbcc”);这个是被测试的内容
//判断是否是数字
Pattern p = Pattern.compile("\d+");
//需要判断的字符串
Matcher m = p.matcher(“12345646”);
if(m.matchers()){
System.out.println(“正确,这是由数字组成的”);
}else{
System.out.println(“错误,不是有数字组成的”);
}

猜你喜欢

转载自blog.csdn.net/weixin_40944832/article/details/88743295