Regex for replacing a single-quote with two single-quotes

前端 未结 8 1494
迷失自我
迷失自我 2020-12-16 09:24

I\'m running into an issue that I think is being caused by needing to double-up on some single quotes inside a string. However, JS\'s string.replace uses RegEx, and I\'ve ne

8条回答
  •  一个人的身影
    2020-12-16 09:57

    I don't know the exact syntax, but you can find that out yourself:

    str.replace(/(?!')'(?!')/g, "''");
    

    Haven't tested this yet, but if it works, it also takes care of only replacing occurances of one single quote in a row. The g modifier is necessary for replacing all ocurrences.

提交回复
热议问题