user1589188 :
In java String
class the matches
tests if a string matches a regex pattern. So obviously it is the entire string against the regex pattern, does that mean \A, \z, ^, $
are redundant here?
If not, please provide examples to show why they are not redundant in this case.
4castle :
They're redundant unless you activate multiline mode, in which case ^
and $
would match the beginning and end of individual lines instead of the whole input.
You can activate multiline mode while using String#matches
by using the embedded flag expression (?m)
inside the regex (usually at the beginning).