public class testReg {
public static void main(String[] args) {
/* String.matches不包含从字符串中搜索的功能 */
//Matcher.find
String check = "(1[358]\\d{9})";
Pattern regex = Pattern.compile(check);
Matcher matcher = regex.matcher("10-20 02:04:43??的姓名:陈女士,他(她)留下了电话:13731977879,请求您现在给他(她)拨电话。");
boolean isMatched = matcher.find();
System.out.println("Matcher.find:"+isMatched);
/*用String.matches*/
String input = "";
System.out.println("String.matches:"+input.matches("(1[358]\\d{9})"));
}
}
String.matches不包含从字符串中搜索的功能
最新推荐文章于 2022-05-19 09:53:16 发布
本文探讨了如何使用正则表达式来匹配特定格式的电话号码,并通过实例展示了实现过程。
836

被折叠的 条评论
为什么被折叠?



