gpt4 book ai didi

javascript - 将引号替换为 guillemets

转载 作者:行者123 更新时间:2023-12-02 18:47:06 25 4
gpt4 key购买 nike

如何用引号(«»)替换文本中的引号 ("")?我尝试了通常的方法(用正则表达式替换)进行替换,但结果很糟糕 - 我不知道如何确定是开引号还是闭引号。

最佳答案

您可以使用正则表达式 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

关于javascript - 将引号替换为 guillemets,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67279857/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com