Welcome to the Java method without the name .matches() ... It tries and matches ALL input. Unfortunately, other languages ββhave followed this example :(
If you want to see if the regular expression matches the input text, use the Pattern , a Matcher and .find() method to match:
Pattern p = Pattern.compile("[az]"); Matcher m = p.matcher(inputstring); if (m.find()) // match
If you really need to see if the input has only lowercase letters, you can use .matches() , but you need to match one or more characters: add + to your character class, as in [az]+ . Or use ^[az]+$ and .find() .
fge Jan 19 '12 at 9:08 2012-01-19 09:08
source share