以下正则验证返回不同的结果,请大家帮忙看下问题,使用的是org.apache.oro.text.regex这个包
[code="java"]PatternCompiler compiler = new Perl5Compiler();
PatternCompiler compiler2 = new Perl5Compiler();
try {
Pattern p = compiler.compile(
".*\\s(and|or)\\s+.*([>=<]|\\slike\\s|\\sbetween\\s)+.*",
Perl5Compiler.READ_ONLY_MASK);
PatternMatcherInput input = new PatternMatcherInput(
"30589 and 7659=7659");
PatternMatcher matcher = new Perl5Matcher();
System.out.println(matcher.contains(input, p)); //这个返回true
System.out.println(matcher.contains(input, compiler2.compile(
".*\\s(and|or)\\s+.*([>=<]|\\slike\\s|\\sbetween\\s)+.*",
Perl5Compiler.READ_ONLY_MASK))); //这个返回false
} catch (MalformedPatternException e) {
System.out.println("error");
}[/code]