JAVA使用正则表达式必须预编译,建议使用oro库
private static String regex = "^[a-zA-Z][a-zA-Z0-9_]{0,50}$";
private static Pattern pattern = new Perl5Compiler().compile(regex, Perl5Compiler.READ_ONLY_MASK
| Perl5Compiler.SINGLELINE_MASK);
在方法里使用
new Perl5Matcher().matches(callback, pattern);
否则正则表达式容易导致JVA崩溃
本文介绍在JAVA中如何安全地使用正则表达式,强调了预编译的重要性,并推荐使用oro库来避免因正则表达式而导致的JAVA崩溃问题。
429

被折叠的 条评论
为什么被折叠?



