On the perlre
's extended patterns page we can read about \K
:
Keep the stuff left of the
\K
, don't include it in $&
Here is the practical example using GNU grep
(which actually keeps stuff right of the \K
):
$ echo "foo bar buzz" | grep -Po "foo \Kbar buzz"
bar buzz
Is there any opposite sequence of \K
?
For example to print just bar
, like:
$ echo "foo bar buzz" | grep -Po "foo \Kbar\X buzz"
bar
echo "foo bar buzz" | sed -E '/foo (bar) buzz/s//\1/'
– Apr 13 '18 at 03:25grep -oP 'foo \K\w+(?= bar)' test.txt
that the accepted answer use here. It seems to me that the answer there also solve the issue here. – Apr 13 '18 at 11:45