我正在学习正则表达式,并且使用以下代码片段进行测试:
String regex = "";
String test = "";
Pattern.compile(regex).matcher(test).find();
但是当我尝试像这样做时:
System.out.println(Pattern.compile("h{2,4}").matcher("hhhhh").find());
它返回了true而不是预期的false。
或者
System.out.println(Pattern.compile("h{2}").matcher("hhh").find());
它返回了 true,而不是预期的 false。
问题出在哪里?也许这不是正确的语句来正确测试正则表达式?
谢谢。