Regular Expression escaping problem!
Hi all,
Well as you know characters such as '*' and '?' are reserved characters in regular expression so I suppose if I want to find the exact character (a '?' for example) in a string, I have to escape it with a backslash:
str=str.replaceAll("\?","a");
In the statement above, I need to replace all question marks with another character but it has a compile error:
Error(116,48): invalid escape character
to my surprise this code does the job while it should be interpreted as
one occurance of the '\' character or nothing at all:
str=str.replaceAll("\\?","a");
What's the problem? what's the general rule on escaping such characters?
|