I am trying to replace curly quotes:
str = \'“I don’t know what you mean by ‘glory,’ ” Alice said.\';
Using:
str.replace(/[
It doesn't work because you're trying to replace the ASCII apostrophe (or single-quote) and quote characters with the empty string, when what's actually in your source string aren't ASCII characters.
str.replace(/[“”‘’]/g,'');
works.
You might have to (or prefer to) use Unicode escapes:
var goodQuotes = badQuotes.replace(/[\u2018\u2019]/g, "'");
That's for funny single quotes; the codes for double quotes are 201C and 201D.
edit — thus to completely replace all the fancy quotes:
var goodQuotes = badQuotes
.replace(/[\u2018\u2019]/g, "'")
.replace(/[\u201C\u201D]/g, '"');
There is now a library called 'SmartQuotes' that will correctly do the job of replacing standard coder's quotes/apostrophes with pretty, typographer's smart quotes -- better than using a simpler search-and-replace as it gets the opening/closing correct.