in reply to Practical use cases for \K in regex
It simplifies.
vssay "foo: bar" =~ s/^ ( \w+: \s* ) bar /${1}baz/xr;
say "foo: bar" =~ s/^ \w+: \s* \K bar /baz/r;
It helps avoid avoid repetition.
vssay "a:b:c:d" =~ s/ :\K [^:]+ (?=:) / uc($&) /xegr;
say "a:b:c:d" =~ s/ : [^:]+ (?=:) / ":" . uc($&) /xegr;
It effectively permits variable-length lookbehinds or makes them faster.
vssay "foo: bar" =~ s/ (?<= ^ \w+: \s* ) bar /baz/xr;
say "foo: bar" =~ s/^ \w+: \s* \K bar /baz/r;
The former was an error when \K was introduced. Even now, it's experimental, and there's a maximum to how much it will look behind this way.
|
|---|