Is negative lookbehind behaving here?
[email protected] (yary) Thu, 3 May 2018 22:38:44 -0700
| Newsgroups | perl.perl6.language |
|---|---|
| Message-ID | <CAG2CFAbYp9AKP6zQ+qpWxt5xL5F9_kaeFwqUEN9D7gFMnWuRDg@mail.gmail.com> |
--001a1143ec4ceef9c3056b5abc90 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable I want to match something anywhere but at the end of a string in one example, or anywhere but at the start of a string in another example. The "except at start" one has me stumped. Not sure if it's me or if I've tickled a bug. perl6 --version This is Rakudo Star version 2018.01 built on MoarVM version 2018.01 implementing Perl 6.c. # Match all but at end- this works as I like > 'abcd' ~~ m/.+<!before $>/ =EF=BD=A2abc=EF=BD=A3 # Match all but at start- this puzzles me, 'a' is after the start of string but still matches > 'abcd' ~~ m/<!after ^>.+/ =EF=BD=A2abcd=EF=BD=A3 # This is a workaround > 'abcd' ~~ m/<!before ^>.+/ =EF=BD=A2bcd=EF=BD=A3 Using a perl5 debugger session, roughly translated negative lookbehind/lookahead work as I expect. DB<1> p 'abcd' =3D~ /(.+(?!$))/ abc DB<2> p 'abcd' =3D~ /((?<!^).*)/ bcd -y --001a1143ec4ceef9c3056b5abc90 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div>I want to match something anywhere but at the end of = a string in one example, or anywhere but at the start of a string in anothe= r example. The "except at start" one has me stumped. Not sure if = it's me or if I've tickled a bug.<br></div><div><br>perl6 --version= <br>This is Rakudo Star version 2018.01 built on MoarVM version 2018.01<br>= implementing Perl 6.c.<br><br></div><div># Match all but at end- this works= as I like<br></div><div>> 'abcd' ~~ m/.+<!before $>/<br>= =EF=BD=A2abc=EF=BD=A3<br><br></div><div># Match all but at start- this puzz= les me, 'a' is after the start of string but still matches<br></div= ><div>> 'abcd' ~~ m/<!after ^>.+/<br>=EF=BD=A2abcd=EF=BD= =A3<br><br></div><div># This is a workaround<br>> 'abcd' ~~ m/&l= t;!before ^>.+/<br>=EF=BD=A2bcd=EF=BD=A3<br></div><div><br>Using a perl5= debugger session, roughly translated negative lookbehind/lookahead work as= I expect.<br><br>=C2=A0 DB<1> p 'abcd' =3D~ /(.+(?!$))/<br>a= bc<br>=C2=A0 DB<2> p 'abcd' =3D~ /((?<!^).*)/<br>bcd<br><b= r clear=3D"all"><div><div class=3D"gmail_signature">-y<br></div></div> </div></div> --001a1143ec4ceef9c3056b5abc90--