4

how to replace ( /" or /') to ( " or ') from the string in javascript. I am referring the content inside the braces. Could anyone give me regular expression for that. Thanks

2 Answers 2

4

You can use one regular expression to replace both:

str = str.replace(/\/(['"])/g, '$1');
Sign up to request clarification or add additional context in comments.

1 Comment

+1 This is cool. I need to use backreferences more in my regexes :)
2
string.replace(/\/"/g, "\"").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.