Matcher.matches()检查
整个输入字符串 是否与正则表达式匹配。
由于您的正则表达式仅与第一个字符匹配,因此它返回
false。
您将改为使用
Matcher.find()。
当然,要找到具体的规范可能会有些棘手,但是它存在:
String.matches()
被定义为与做相同的事情Pattern.matches(regex, str)
。Pattern.matches()
依次定义为Pattern.compile(regex).matcher(input).matches()
。Pattern.compile()
返回Pattern
。Pattern.matcher()
返回一个Matcher
Matcher.matches()
记录如下(强调我的意思):
尝试根据图案匹配 整个 区域。



