I note that PCRE2 does support \K
in lookarounds, with what seem to be reasonably sane semantics. I think we should consider the possibility of supporting them, with similar semantics. @tonycoz does this sound plausible?
Here are some relevant docs from pcre2-10.35:
[...] In PCRE2, \K is acted upon when it occurs inside positive as-
sertions, but is ignored in negative assertions. Note that when a pat-
tern such as (?=ab\K) matches, the reported start of the match can be
greater than the end of the match. Using \K in a lookbehind assertion
at the start of a pattern can also lead to odd effects. For example,
consider this pattern:
(?<=\Kfoo)bar
If the subject is "foobar", a call to pcre2_match() with a starting
offset of 3 succeeds and reports the matching string as "foobar", that
is, the start of the reported match is earlier than where the match
started.
.. and specifically for substitutions:
Matches in which a \K item in a lookahead in the pattern causes the
match to end before it starts are not supported, and give rise to an
error return. For global replacements, matches in which \K in a lookbe-
hind causes the match to start earlier than the point that was reached
in the previous iteration are also not supported.
These are the primary test cases:
"ab" =~ /(?=a\Kb)ab/
$& eq 'b'
"ac" =~ /(?!a\Kb)ac/
$& eq 'ac'
"abcd" =~ /^abc(?<=b\Kc)d/
$& eq 'cd'
"abcd" =~ /^abc(?<!b\Kq)d/
$& eq 'abcd'
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4