vegedezozu
vegedezozu

Reputation: 75

negative lookahead between and across multiple lines

I'm trying to find lines in some text that does not contain 403, between the BEGIN and END. I thought a negative lookahead would be the solution but can't seem to get it to work across multiple lines, this is what I thought might work:

BEGIN(?!403).*?END

This is the text to search across:

BEGIN
403
403
403
301
END

Expected result:

301

I can get it to work with the following, but I want to make it explicitly search only between BEGIN and END:

^((?!403|BEGIN|END).)*$

Upvotes: 2

Views: 166

Answers (1)

Alireza
Alireza

Reputation: 2123

Tty this: (?!^403$)^.*

Demo

For grep use: grep -P '(?!^403$)^.*' test.txt

Upvotes: 1

Related Questions