On Thu, Aug 22, 2019 at 6:11 PM yary <[email protected]> wrote:
> Perl 6 is doing the right thing. The dot matches any character. In
> this case, matching the final ':'. The next bit of the regex says the
> cursor has to be after 1:, and indeed, after matching the ':' the
> cursor is after '1:', so the substitution succeeds.
>
My real use case, that I tried to provide a simplified example of, was to
process some pretty-printed JSON. Less simplified this time, I wanted to
change all "foo": "whatever" strings to "foo": "*". In Perl 5 I would have
done:
s/(?<="foo": ")[^"]+/*/;
Trying to express this in Perl 6, I thought "lookbehind" would naturally
translate to a "before" assertion:
s/<?before '"foo": "'><-["]>+/*/;
...but that didn't work. Various other attempts led to the simplified
example I originally provided.
Long story short, it seems that a Perl 5 (?<=...) lookbehind translates to
a Perl 6 <?after ...> assertion, and likewise a Perl 5 (?=...) lookahead
translates to a Perl 6 <?before ...> assertion. The terminology just
confused me due to my prior Perl 5 experience.