neo_the_1
March 20th, 2008, 08:24 AM
hello,
i have a string and i need to push the '\' char before all regex special chars like $ . * and so on.
any idea how to do that ?
thanks
keang
March 20th, 2008, 09:41 AM
The backslash character marks the start of an escape sequence so if you actually want a backslash character to appear in your string you need to use a double backslash ie '\\' which is the escape sequence for a single backslash character.
spoon!
March 20th, 2008, 04:21 PM
If you are using Java 1.5+ you should use Pattern.quote() to quote a string. Otherwise, just put \Q and \E around the string (that would be "\\Q" and "\\E" of course, when written out). These special forms quote the things between them.