I have a string and I need to replace all the ' and etc to their proper value
I am using
var replace = str.replace(new RegExp("[']", "g"), "'");
To do so, but the problem is it seems to be replacing ' for each character (so for example, ' becomes '''''
Any help?
Use this:
[']is a character class. It means any of the characters inside of the braces.This is why your
/[']/regex replaces every single char of'by the replacement string.If you want to use
new RegExpinstead of a regex literal:This has no benefit, except if you want to generate regexps at runtime.