How to replace a plus character using Java's String.replaceAll method

后端 未结 8 1891
别跟我提以往
别跟我提以往 2020-12-28 11:50

What\'s the correct regex for a plus character (+) as the first argument (i.e. the string to replace) to Java\'s replaceAll method in the String class? I can\'t

8条回答
  •  一向
    一向 (楼主)
    2020-12-28 12:19

    Say you want to replace - with \\\-, use:

     text.replaceAll("-", "\\\\\\\\-");
    

提交回复
热议问题