it seems that I am completely blocked because I do not know why this code always prints “true”:
public class Main {
public static void main(String[] args) {
Pattern p = Pattern.compile("[1-9]{1,2}");
Matcher m = p.matcher("1234567");
System.out.println(m.find());
}
}
Matcher.findwill perform a partial match on theStringso will always find a digit to match. You need to useMatcher.matches()to match the fullString: