Search code examples
javaregexeclipsespecial-characters

Regular expression is working online and not in Eclipse


I have escaped special characters and verified that the string passed to the Pattern is what I want.
I printed it on the screen and all double slashes were single again.

Particularly, I want these to be found:

\z.\s.\f.jtuy   \z.yu    \aw.o  

lambda expressions. My regex is

(\\[a-z]{1,}\.){1,}[a-z]{1,}

and it - as I said - is working online. But why not in eclipse?
Do double backslashes get to the Pattern unchanged?
Is there any replacement for them? Thanks.


Solution

  • If you mean "in the Java sourcecode" by saying "in Eclipse" you might need to use four backslashes: four backslashes will become two backslashes for the regex engine. You need to escape the backslash twice: once for the Java string and the second time for the regex engine.