【发布时间】:2017-10-03 09:58:28
【问题描述】:
我有以下文字。
^0001 HeadOne
@@
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been theindustry's standard dummy text ever since the 1500s, when an unknown printer took a galley of typeand scrambled it to make a type specimen book.
^0002 HeadTwo
@@
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been theindustry's standard dummy text ever since the 1500s, when an unknown printer took a galley of typeand scrambled it to make a type specimen book.
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been theindustry's standard dummy text ever since the 1500s, when an unknown printer took a galley of typeand scrambled it to make a type specimen book.
^004 HeadFour
@@
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
^0004 HeadFour
@@
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been theindustry's standard dummy text ever since the 1500s, when an unknown printer took a galley of typeand scrambled it to make a type specimen book.
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been theindustry's standard dummy text ever since the 1500s, when an unknown printer took a galley of typeand scrambled it to make a type specimen book.
下面是我用来查找的正则表达式。
@@([\n\r\s]*)(.*)([\n\r\s]+)\^
但这仅捕获^0001 和^0003,因为它们只有一个段落,但在我的文本中有多个段落内容。
我正在使用 VS 代码,有人可以告诉我如何在 VS 代码或 NPP 中使用 REGEX 捕获此类多参数字符串。
谢谢
【问题讨论】:
-
\s 通常是空格,我会尝试删除它或添加 * 来表示零个或多个
-
预期的匹配是什么,为什么? @Calvin,在 VSCode 中,
\s不匹配换行符。如何定义尾随边界?@@总是在行首吗? -
@WiktorStribiżew 使用
@@时直接匹配 -
@WiktorStribiżew,我正在尝试匹配
@@和^之间的内容,让它成为任意数量的段落...... -
我刚刚在VSCode中尝试了
@@.*(?:[\s\r]?(?!\s*\^).*)*,它突出显示了@@之后的所有段落。尝试。我的 VSCode 版本是 1.16.1。要确保@@仅在行首匹配,请在模式前添加^。
标签: regex visual-studio-code find-replace