Matcher.matches()
checks to see if the entire input string is matched by the regex.
Since your regex only matches the very first character, it returns false
.
You’ll want to use Matcher.find()
instead.
Granted, it can be a bit tricky to find the concrete specification, but it’s there:
String.matches()
is defined as doing the same thing asPattern.matches(regex, str)
.Pattern.matches()
in turn is defined asPattern.compile(regex).matcher(input).matches()
.Pattern.compile()
returns aPattern
.Pattern.matcher()
returns aMatcher
Matcher.matches()
is documented like this (emphasis mine):
Attempts to match the entire region against the pattern.