Artificial intelligent assistant

Opposite of \K, to keep the stuff right 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

In this case, zero-width lookahead `(?=...)` does what you want:


$ echo foo bar buzz | grep -Po "foo \Kbar(?= buzz)"
bar


It does require some extra parentheses. There is no single-character escape for lookahead the way there is for `\K`.

`\K` is really just a zero-width lookbehind for everything so far, so this is also equivalent to


echo foo bar buzz | grep -Po "(?<=foo )bar(?= buzz)"


which I find easier to follow personally.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 16abe778cc751aec261a75e2e0990620