How to replace curly quotation marks in a string using Javascript?

前端 未结 3 472
挽巷
挽巷 2020-12-05 07:02

I am trying to replace curly quotes:

str = \'“I don’t know what you mean by ‘glory,’ ” Alice said.\';

Using:

str.replace(/[         


        
3条回答
  •  抹茶落季
    2020-12-05 07:55

    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, '"');
    

提交回复
热议问题