【问题标题】:VS Code find and replace text containing new lines using regex [duplicate]VS Code使用正则表达式查找和替换包含新行的文本[重复]
【发布时间】:2020-02-29 13:07:23
【问题描述】:

以本文为例:

Lorem ipsum dolor, sit START amet consectetur adipisicing elit.
Doloribus, aspernatur! Illum id sapiente STOP eligendi, autem,
consequuntur START asperiores illo atque aut, incidunt quia numquam
beatae esse hic dolor odit minus STOP iure!

我尝试捕获并替换位于 START 和 STOP 词之间的文本,其中可能包含新行。

我读过 VS 代码对正则表达式使用 Rust 风格或 Javascript 风格,所以我都尝试了:

START((?s:.*?))STOP

START([^]*?)STOP

但它们都不起作用(而它们与在线正则表达式测试器配合得很好)。 第一个被认为是无效的,第二个不返回结果。

我应该使用哪个正则表达式来实现这一点?

谢谢!

【问题讨论】:

    标签: replace visual-studio-code


    【解决方案1】:

    使用[\w\W] 匹配任何字符,包括换行符。您的正则表达式变为:

    START([\w\W]+?)STOP
    

    截图:

    【讨论】:

    • 不错的反对票!有什么原因吗?
    猜你喜欢
    • 2023-02-11
    • 2012-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-04
    • 1970-01-01
    • 2020-08-09
    • 2021-04-22
    相关资源
    最近更新 更多