【问题标题】: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<'

【讨论】:

    猜你喜欢
    • 2019-10-31
    • 1970-01-01
    • 2019-11-02
    • 2023-03-23
    • 1970-01-01
    • 1970-01-01
    • 2014-09-07
    • 2012-03-12
    相关资源
    最近更新 更多