Reputation: 108
I want to check if the Regex defined in Java is valid by Python.
But the Regex in the two languages are little different.
For example, to parse the character dot (.
)
"\." # Python version
"\\." # Java version
Is there any way to check Java regex in Python?
Upvotes: 0
Views: 197
Reputation: 40510
Regex are the same in java and python. The difference you pointed out is due to the way java compiler handles string constants.
Backslash has special meaning as an escape character, so, to include a backslash itself into a String literal, you have to repeat it twice. Thus "\\."
to express a string constant "\."
Try this: System.out.println(Pattern.compile("\\.").toString());
Upvotes: 1