Bruno Sant Ana wrote:but if I uncomment the line m.reset(); the output change to:
false true aaaaaaab
Interesting question. It has to do with how regex (or rather
Matcher) "positions" when attempting a match.
I suspect (though I'm not
absolutely sure about this) that the
matches() positions to the point
after it determined that there was no match, which I suspect is after any number of 'a's NOT followed by "b$", which would be the first character following all those 'a's. And, since your
pattern is "a*b", not "a+b", the 'b' matches the pattern.
Like I say, I understand the result, but you might want a second opinion of my interpretation.
Winston
PS: If you understand regexes, then you need to also understand that
matches("a*b") is the same as
find("^a*b$") (well, almost).