In java Regex i want to replace all the special characters to escape sequence.how can i do. Example ::
//special chars ex "dd[u]i.* " to "dd//[u//]i//.//*"
In java Regex i want to replace all the special characters to escape sequence.how can i do. Example ::
//special chars ex "dd[u]i.* " to "dd//[u//]i//.//*"
To escape all special regexp control characters this method can be used:
Matcher.quoteReplacement(String s)
It returns a regular expression that matches exact s
.
This comes from the javadoc:
Returns a literal replacement String for the specified String. This method produces a String that will work as a literal replacement s in the appendReplacement method of the Matcher class. The String produced will match the sequence of characters in s treated as a literal sequence. Slashes ('\') and dollar signs ('$') will be given no special meaning.
To split or treat special characters in java pattern as normal one. You have to backshlas it.
\\.
; \\*
it might be treat now as '.' and '*'.