For expression (?<!foo)
,Negative Lookbehind ,asserts that what immediately precedes the current position in the string is not foo.
Now to match string not ending with characters abc
.
The formal expression is \w+(?<!abc)\b
or \b\w+(?<!abc)\b
.
echo "xxabc jkl" | grep -oP '\w+(?<!abc)\b'
jkl
Let's try another form: \w+\b(?<!abc)
.
echo "xxabc jkl" | grep -oP '\w+\b(?<!abc)'
jkl
It get correct answer too.
In my opinion, \w+\b(?<!abc)
is not a Negative Lookbehind,nothing behind (?<!abc)
,it can't called Negative Lookbehind.
1.Is expression \w+\b(?<!abc)
a Negative Lookbehind?
2.Why \w+\b(?<!abc)
has the same effct as \w+(?<!abc)\b
?