Replace Both Double and Single Quotes in Javascript String

jmease picture jmease · Oct 13, 2011 · Viewed 127.3k times · Source

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 problems later and I need to replace all of the single and double quotes. I can successfully get rid of one or the other by doing:

this.Vals.replace(/\'/g, "")   To get rid of single quotes

or

this.Vals.replace(/\"/g, "")   To get rid of double quotes

How do I get rid of both of these in the same string. I've tried just doing

this.Vals.replace(/\"'/g, "")

and

this.Vals.replace(/\"\'/g, "")

But then neither get replaced.

Answer

Joe picture Joe · Oct 13, 2011

You don't escape quotes in regular expressions

this.Vals.replace(/["']/g, "")