I am learning regex, and for testing purposes, I use the following code snippet:
String regex = "";
String test = "";
Pattern.compile(regex).matcher(test).find();
but when I try something like this:
System.out.println(Pattern.compile("h{2,4}").matcher("hhhhh").find());
it returns true, not false as expected.
or
System.out.println(Pattern.compile("h{2}").matcher("hhh").find());
it returns true, not false as expected.
What is the problem? Maybe these are incorrect statements for the correct validation of the regular expression?
thank.
source
share