Javascript replace “ ' ” with “ '' ”

后端 未结 7 743
陌清茗
陌清茗 2021-01-22 12:24

I\'m trying to replace the \"\'\" character with the \"\'\'\" string using the replace method, like this:

temp.replace(\"\\\'\", \"\'\'\");

but

7条回答
  •  佛祖请我去吃肉
    2021-01-22 12:47

    So it's basically changing the single quote character with 2 single quote characters, right? If that's the case you might wanna use the global flag, g at the end of yoir Regular Expression and assing it back to your value (temp)

    temp = temp.replace(/'/g,"''");
    

提交回复
热议问题