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
Note that this is not the Java regular expression engine that requires the double backslashes, but the Java compiler. When you write the following in Java source code:
"(forumdisplay.php\\?.*page=%CURRENTPAGE%)"
the Java compiler interprets this as the string:
(forumdisplay.php\?.*page=%CURRENTPAGE%)
The Java regular expression engine then does exactly the same thing as other regular expression engines - the question mark (because it is escaped) is treated literally.
A similar thing happens in Python - the two strings below are identical:
r"(forumdisplay.php\?.*page=%CURRENTPAGE%)"
"(forumdisplay.php\\?.*page=%CURRENTPAGE%)"
This is using the Python r
notation for a "raw" string where backslashes are not interpreted by the compiler.