用guillemets替换引号
如何""用 guillemets ( «and »)替换文本中的引号 ( ) ?我尝试了通常的替换方法(用正则表达式替换),但结果很糟糕 - 我不知道如何确定是开头引用还是结尾引用。
回答
您可以replace使用正则表达式 -/"(.*?)"/g替换整个“单词”。
console.log(
'"word1" word2 "word3"'.replace(/"(.*?)"/g, '«$1»'))
或者
console.log(
'"word1" word2 "word3"'.replace(/"(.*?)"/g, (a, b) => `«${b}»`));
https://regex101.com/r/9s68XL/1