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

前端 未结 8 1464
迷失自我
迷失自我 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:58

    You don't need to use RegExp.

    String patterm version:

    str.replace("'", "''", 'g')
    

    RegExp pattern version:

    str.replace(/'/g, "''")
    

    Here you have some useful RegExp links:

    • RegExp Tutorial
    • Regular Expression Basic Syntax Reference
    • RegExp Build&Testing Online Tool

提交回复
热议问题