【问题标题】:Replace a String inside quotes替换引号内的字符串
【发布时间】:2022-11-17 05:53:03
【问题描述】:
我需要一个用于 Javascript 的正则表达式来替换字符串(例如 >//<),如果它在任何类型的引号内。例如
>This is a test "With a text including // and more" for replacement<
我无法使用正则表达式规则的组合
我不擅长那个,这对你们中的一些人来说很容易;)
【问题讨论】:
标签:
javascript
regex
replace
【解决方案1】:
是你期待的吗?
$ node
Welcome to Node.js v19.0.0.
Type ".help" for more information.
> var text = '>This is a test "With a text including // and more" for replacement<'
undefined
> text.replace(/".*"/, "foobar")
'>This is a test foobar for replacement<'