I can not check the banal expression. Result Not matched!

What is missing in this code?

 public static void main(String[] args) { doMatch("abc"); } public static void doMatch(String value){ Pattern pattern = Pattern.compile("[a-zA-Z]"); Matcher matcher = pattern.matcher(value); if(matcher.matches()){ System.out.println(value + " Matched!"+" "+ matcher.matches()); } else if(!(matcher.matches())){ System.out.println(value + " :Not matched!"+" "+ matcher.matches()); } } 

    1 answer 1

    Your regular game is looking for only a single occurrence of a character from a-zA-Z For example, when you call matcher.find() you will return true and there will be three matches - a , b , c . matcher.matches() will return true when the entire string will fit the regular schedule. To do this, you need to make a regular [a-zA-Z]+ , for example, like this: [a-zA-Z]+