I would like to do something like this:
s = s.replace(/(”)/g, '"'); // need to replace with double quotes
s = s.replace(/(“)/g, '"'); // need to replace with double quotes
s = s.replace(/(’)/g, "'"); // need to replace with single quotes
But for me this does not work. I tried all the ways.
I would like to do something like this:
s = s.replace(/(”)/g, '"'); // need to replace with double quotes
s = s.replace(/(“)/g, '"'); // need to replace with double quotes
s = s.replace(/(’)/g, "'"); // need to replace with single quotes
But for me this does not work. I tried all the ways.
Share Improve this question edited Sep 4, 2020 at 10:41 Flux 11k6 gold badges62 silver badges108 bronze badges asked Sep 24, 2012 at 22:57 niminimi 5,50718 gold badges62 silver badges90 bronze badges2 Answers
Reset to default 3You can use Unicode values in replace:
s = s.replace(/\u201C|\u201D/g, '"'); // for “ or ”
s = s.replace(/\u2019/g, "'"); // for ’
DEMO: http://jsfiddle/uM2fY/
So we open console, and see:
>>> 'test&rqduo;foo'.replace(/&rqduo;/g, '\"' );
test"foo
and with braces:
>>> 'test&rqduo;foo'.replace(/(&rqduo;)/g, '\"' );
test"foo
Everything work just like you thought. Please, check your input strings.