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

后端 未结 8 1879
别跟我提以往
别跟我提以往 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:29

    If you want a simple string find-and-replace (i.e. you don't need regex), it may be simpler to use the StringUtils from Apache Commons, which would allow you to write:

    mystr = StringUtils.replace(mystr, "+", "plus");
    

提交回复
热议问题