在Java
Regex中,
Matcher.find()(在String中的任意位置找到匹配项)和
Matcher.matches()(与整个String匹配)之间存在区别。
String仅具有一个
matches()方法(实现等效于以下代码:)
Pattern.compile(pattern).matcher(this).matches();,因此您需要创建一个与完整String匹配的模式:
System.out.println("I end with a number 4".matches("^.*\d$"));
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)