Since not all regex flavors support lookarounds, Perl introduced the match reset -
\K (bolded is mine):
\Kresets the starting point of the reported match. Any previously consumed characters are no longer included in the final match
To make the explanation short, consider the following simple Regex:
When "b" is matched,
\K tells the Regex engine to pretend that the match attempt started at this position.
~$ echo 'hello world' | grep -oP 'hello \K(world)' world ~$ echo 'hello world' | grep -oP 'hello (world)' hello world
Top comments (0)