'' this is a "test' there is another "test' 第二种情况 /\b'/ Regex Demo-6ren">
gpt4 book ai didi

javascript - 正则表达式匹配双引号内的单引号(单独)?

转载 作者:行者123 更新时间:2023-11-28 12:26:40 28 4
gpt4 key购买 nike

如何编写正则表达式来匹配它(参见箭头):

"this is a ->'<-test'" // note they are quotes surrounding a word

还有其他匹配的吗?

"this is a 'test->'<-"

在 JavaScript 中? (然后,比如说,用双引号替换它们?)

我想用两个正则表达式分别匹配它们。

最佳答案

第一种情况

/'\b/

Regex Demo

"this is a 'test' there is another 'test'".replace(/'\b/g, '"'))
=> this is a "test' there is another "test'

第二种情况

/\b'/

Regex Demo

"this is a 'test' there is another 'test'".replace(/\b'/g, '"'))
=> this is a 'test" there is another 'test"

关于javascript - 正则表达式匹配双引号内的单引号(单独)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27775787/

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