Replacing single '\' with '\\' in Java

后端 未结 6 1599
离开以前
离开以前 2020-12-07 01:23

How do I replace a single \'\\\' with \'\\\\\'? When I run replaceAll() then I get this error message.

Exception in t         


        
6条回答
  •  伪装坚强ぢ
    2020-12-07 02:03

    \ is also a special character in regexp. This is why you should do something like this:

        str = str.replaceAll("\\\\", "\\\\\\\\");
    

提交回复
热议问题