57

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.

1
  • Both methods work like a charm. I will mark an answer as soon as it will let me. Thanks! Commented Oct 13, 2011 at 21:01

4 Answers 4

133

You don't escape quotes in regular expressions

this.Vals.replace(/["']/g, "")
Sign up to request clarification or add additional context in comments.

Comments

15
mystring = mystring.replace(/["']/g, "");

Comments

5

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

"\"foo\"\'bar\'".replace(/("|')/g, "")

Comments

4

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.