【发布时间】:2017-07-05 04:18:48
【问题描述】:
让我先说文本是逐行输入的。前瞻将不起作用。
因此,对于以下内容,我应该运行两个单独的正则表达式搜索。
这大约是我在大脑受伤之前使用正则表达式得到的结果:
案例一:
(?<!Case 2.)[\s\S]*?This line should match\.
案例 2:
(?<!Case 1.)[\s\S]*?This line should match\.
第一次正则表达式搜索应该为匹配文本的每一行返回一个成功的匹配:“This line should match.”在“案例 1”行之后。但在“案例 2”行之前。 (为了清楚起见,此处用括号 [])
第二个正则表达式搜索应该为匹配文本的每一行返回一个成功的匹配:`"This line should match."在“案例 2”行之后。但在“新序列开始”行之前。 (为了清楚起见,这里的括号())
在实际文本中,括号和括号不存在,并且两组不同的行在文本上是相同的。
正在搜索的文本:
Start of new sequence.
Random line(s).
Case 1.
Random line(s).
[This line should match.]
Random line(s).
[This line should match.]
Random line(s).
Case 2.
Random line(s).
(This line should match.)
Random line(s).
(This line should match.)
Random line(s).
Start of new sequence.
Random line(s).
Case 1.
Random line(s).
[This line should match.]
Random line(s).
[This line should match.]
Random line(s).
Case 2.
Random line(s).
(This line should match.)
Random line(s).
(This line should match.)
【问题讨论】:
标签: regex