Sometimes when using java you may want to search in a string or split a string using some other string which may have characters which corresponds to special characters in regular expressions. Thus you may want to escape those characters. There are two ways.
1. Escape the special characters one by one.
in this case all you have to do is to put a “\” infront of each special character.
eg: "12+3" => "12\+3"
2. Escape the whole string at one go.
This asks the regular expression parser to ignore any special characters in the string. This is also very simple as the first method. All you have to do is to put “\Q” in front of the string and “\E” at the end of the string.
eg: " C++ is a (highlevel) programming language" => "\Q C++ is a (highlevel) programming language\E"
This is however already available as a function in java
Naturally you can use this method to make parts of a string escape as a regular expression.