将正则表达式转换为兼容java的正则表达式的简便方法? [英] Easy way to convert regex to a java compatible regex?
问题描述
我在Python / Ruby / PHP中定义的正则表达式是这样的
I have a regex defined in Python/Ruby/PHP that is like this
"(forumdisplay.php\?.*page=%CURRENTPAGE%)"
当我为Java做的时候,我必须双重逃脱该问号是 \\?
When I do it for Java, I have to double escape that question mark to \\?
如下所示:
"(forumdisplay.php\\?.*page=%CURRENTPAGE%)";
我可以使用哪种功能自动执行此操作?或者我是否需要更改所有正则表达式以使用Java正则表达式引擎?
Is there a function I can use to do that automatically? Or would I need to change all my regexes over to work with the Java regex engine?
推荐答案
尝试使用此在线工具:< a href =http://www.regexplanet.com/advanced/java/index.html\"rel =noreferrer> http://www.regexplanet.com/advanced/java/index.html
Try this online tool out: http://www.regexplanet.com/advanced/java/index.html
它采用正常的正则表达式并输出兼容java的字符串表达式。节省了大量的时间来转换巨大的正则表达式字符串。
It takes your normal regular expression and outputs the java-compatible string expression. Saved me tons of time converting huge regex strings myself.
请注意,并非所有正则表达式都适用于java。我已经看到奇怪的PHP验证正则表达式,它在java模式匹配中的行为方式不同。
Note that not all regex expressions work in java. I've seen weird php validation regex that simply behaves differently in java pattern matching.
这篇关于将正则表达式转换为兼容java的正则表达式的简便方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!