Issue
As a simplified example I have printf "abc\ndef\nghi\n" | grep -oPz '\w{2}(?=c|f|i)\n'
and that does not match anything, however grep -oPz '\w{2}(?=(c|f|i)\n)'
does. Why is that? I need the newline in the output.
Desired output is to match the rows and output them without the lookahead part eg. ab\n
Solution
ab
means a
followed by b
, and continue matching after the b
.
a(?=b)
means a
followed by b
, and continue matching after the a
.
So, for (?=c|f|i)\n
to match, there must be a position that matches both c
and \n
, both f
and \n
, or by both i
and \n
. That's impossible.
Answered By - ikegami