Javascript replace “ ' ” with “ '' ”

后端 未结 7 678
陌清茗
陌清茗 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:37

    The trick is quoting each string with the other quote character:

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

    Edit: Ben Lee is correct about the regex, updated above. However, I still gather it that you want to replace with " (one double quote), not '' (two single quotes).

提交回复
热议问题