Replace all plus signs (+) with space in a string

后端 未结 1 1682
长情又很酷
长情又很酷 2020-12-09 03:23

I\'m not sure how to escape \'+\' in regex. Plus can come multiple times in i so we need to replace all + in the string. Here\'s what I have:

相关标签:
1条回答
  • 2020-12-09 04:03

    The + character has special significance in regular expressions. It's a quantifier meaning one or more of the previous character, character class, or group.

    You need to escape the +, like this:

    i.replace(new RegExp("\\+","g"),' ')...
    

    Or more simply, by using a precompiled expression:

    i.replace(/\+/g,' ')...
    
    0 讨论(0)
提交回复
热议问题