Pattern.matcher(String str)
returns a Matcher that can find patterns
in the String.
Pattern.matches(String str)
tests if
the entire String matches the pattern.
If you want to work with Regular expressions, get a copy of
Expresso[
^] - it's free, and it examines and generates Regular expressions.
It will tell you exactly what "
[amn]?
" means:
Any character in this class: [amn], zero or one repetitions
So a single character in the class will match as a whole string, but two characters can't.
Try: "
[amn]*
" instead.