Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 正则表达式仅在前面有行X时匹配行Z,但在前面有行Y时不匹配行Z_Regex - Fatal编程技术网

Regex 正则表达式仅在前面有行X时匹配行Z,但在前面有行Y时不匹配行Z

Regex 正则表达式仅在前面有行X时匹配行Z,但在前面有行Y时不匹配行Z,regex,Regex,让我先说一下,这篇文章是逐行输入的。向前看是行不通的 因此,对于以下内容,我应该运行两个单独的正则表达式搜索 这是我在大脑受伤之前用正则表达式得到的结果: 案例1: (?<!Case 2.)[\s\S]*?This line should match\. 你怎么能想象在你还没有的模式之前(或之后)的条件匹配呢? 因此,如果您收到该行,则可以匹配该模式(使用前瞻或任何其他构造) 使用前瞻,我只是建议: (?<=Case 1\.).*?(\[This line should match

让我先说一下,这篇文章是逐行输入的。向前看是行不通的

因此,对于以下内容,我应该运行两个单独的正则表达式搜索

这是我在大脑受伤之前用正则表达式得到的结果:

案例1:

(?<!Case 2.)[\s\S]*?This line should match\.

你怎么能想象在你还没有的模式之前(或之后)的条件匹配呢?
因此,如果您收到该行,则可以匹配该模式(使用前瞻或任何其他构造)

使用前瞻,我只是建议:

(?<=Case 1\.).*?(\[This line should match.\]).*?(?=Case 2\.)

(?不,这与我想做的还不太接近。首先,我不能使用lookahead,因为我在聊天日志上运行此操作,因为信息进来时。当它到达该行时,它应该匹配,它应该是最后一行可以读取。
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.)
(?<=Case 1\.).*?(\[This line should match.\]).*?(?=Case 2\.)
(?<=Case 2\.).*?(\(This line should match.\)).*?(?=Start of new sequence\.)