Easy way to convert regex to a java compatible regex?

后端 未结 4 2089
花落未央
花落未央 2021-01-01 21:30

I have a regex defined in Python/Ruby/PHP that is like this

\"(forumdisplay.php\\?.*page=%CURRENTPAGE%)\"

When I do it for Java, I have to

4条回答
  •  太阳男子
    2021-01-01 22:22

    A good start is usually to just do a "find replace all" of "\" with "\\".

    You aren't really doing a change to make this work with the java regex engine. You are just having to deal with the pains of storing a regex in a Java String... You could do this in a function, but that would make more code to maintain. I would suggest doing a find replace as described above...

提交回复
热议问题