Converting ″Straight Quotes″ to “Curly Quotes”

后端 未结 7 1074
旧时难觅i
旧时难觅i 2020-12-13 19:53

I have an application which uses a Javascript-based rules engine. I need a way to convert regular straight quotes into curly (or smart) quotes. It’d be easy to just do a <

7条回答
  •  离开以前
    2020-12-13 20:21

    The following just changes every quote by alternating (this specific example however would leave out the orphaned quotes).

    str.replace(/\"([^\"]*)\"/gi,"“$1”");
    

    Works perfectly, as long as the text you're texturizing isn't already screwed up with improper use of the double quote. In English, quotes are never nested.

提交回复
热议问题