卡德姆
我试图找到任何以单词开头,后跟 a '
,然后是 word( /\w'\w/
) 的内容。例如(i'm, it's, what's, there's, John's),以John's为例,它会匹配n's
。这是完美的,但是一旦匹配,我只想替换'
and 不替换n
and s
。
代码狂人
您可以使用捕获组。
([^'])'([^'])
| |________ Group 2
|
|______________ Group 1
let arr = [`i'm`, `it's`, `what's`,`there's`,`John's`]
arr.forEach(e=>{
e = e.replace(/([^'])'([^'])/g, "$1$2")
console.log(e)
})
- 按
Ctrl+f
添加正则表达式模式并选择.*
选项。
- 在第二个输入框中添加替换值
$1$2
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
编辑于
我来说两句