Replace Both Double and Single Quotes in Javascript String

前端 未结 4 1280
醉话见心
醉话见心 2020-12-25 10:10

I am pulling in some information from a database that contains dimensions with both \' and \" to denote feet and inches. Those characters being in my string cause me proble

相关标签:
4条回答
  • 2020-12-25 10:48

    You don't escape quotes in regular expressions

    this.Vals.replace(/["']/g, "")
    
    0 讨论(0)
  • 2020-12-25 10:48
    mystring = mystring.replace(/["']/g, "");
    
    0 讨论(0)
  • 2020-12-25 10:48

    You don't need to escape it inside. You can use the | character to delimit searches.

    "\"foo\"\'bar\'".replace(/("|')/g, "")
    
    0 讨论(0)
  • 2020-12-25 10:51

    Try this.Vals.replace(/("|')/g, "")

    0 讨论(0)
提交回复
热议问题