The Java replaceall () method uses four backslash to represent a backslash.
For example, str1 = "AA \ BBB"; str2 = "AA 'bbb ";
To replace it with str1 = "AA \ BBB"; str2 = "AA \ 'bbb ";
It must be replaced as follows:
Str1 = str1.replaceall ("\\\\","\\\\\\\\");
Str2 = str2.replaceall ("'","\\\\'");
The reason is as follows:
The string replaceall () method is actually matched using regular expression rules,
\\\\, The Java Parsing is \ to the regular expression, the regular expression is converted again, convert \ \
That is to say, the regular expression must be used in Java to indicate a \. Four \
If you want to represent \, you need to write 8 \
Therefore, if it is written as str1 = str1.replaceall ("\\","\\\\");
A regular expression error is reported.
This article from "Yu Hong produced" blog, please be sure to keep this source http://5fresh.blog.51cto.com/5472694/1541570