Re: Is negative lookbehind behaving here?

[email protected] (Timo Paulssen) Fri, 4 May 2018 18:40:20 +0200
Newsgroups perl.perl6.language
Message-ID <[email protected]>
--------------5B4ACBDF8F79BD3A8250EF63
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable

Yes, you've encountered a bug. It's got these two tickets:

https://rt.perl.org/Public/Bug/Display.html?id=3D124898
https://rt.perl.org/Public/Bug/Display.html?id=3D131964

I've got a branch in nqp and rakudo that I'll merge very soon that fixes
both of these bugs.

Until then you can switch $ and ^, but when the version lands that fixes
the bug, that'll "misbehave" again. I think having ^|$ in the
before/after assertions, i.e. literally match either the beginning or
the end, should work with pre-fix and post-fix versions, as you cannot
have text after the end of the string for example.

Hope that helps!
=C2=A0 - Timo


On 04/05/18 07:38, yary wrote:
> 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.
>
> =C2=A0 DB<1> p 'abcd' =3D~ /(.+(?!$))/
> abc
> =C2=A0 DB<2> p 'abcd' =3D~ /((?<!^).*)/
> bcd
>
> -y


--------------5B4ACBDF8F79BD3A8250EF63
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable

<html>
  <head>
    <meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Dutf=
-8">
  </head>
  <body text=3D"#000000" bgcolor=3D"#FFFFFF">
    <p>Yes, you've encountered a bug. It's got these two tickets:</p>
    <p><a class=3D"moz-txt-link-freetext" href=3D"https://rt.perl.org/Pub=
lic/Bug/Display.html?id=3D124898">https://rt.perl.org/Public/Bug/Display.=
html?id=3D124898</a><br>
      <a class=3D"moz-txt-link-freetext" href=3D"https://rt.perl.org/Publ=
ic/Bug/Display.html?id=3D131964">https://rt.perl.org/Public/Bug/Display.h=
tml?id=3D131964</a></p>
    <p>I've got a branch in nqp and rakudo that I'll merge very soon
      that fixes both of these bugs.</p>
    <p>Until then you can switch $ and ^, but when the version lands
      that fixes the bug, that'll "misbehave" again. I think having ^|$
      in the before/after assertions, i.e. literally match either the
      beginning or the end, should work with pre-fix and post-fix
      versions, as you cannot have text after the end of the string for
      example.</p>
    <p>Hope that helps!<br>
      =C2=A0 - Timo<br>
    </p>
    <br>
    <div class=3D"moz-cite-prefix">On 04/05/18 07:38, yary wrote:<br>
    </div>
    <blockquote type=3D"cite"
cite=3D"mid:[email protected]=
l.com">
      <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 another 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>&gt; 'abcd' ~~ m/.+&lt;!before $&gt;/<br>
          =EF=BD=A2abc=EF=BD=A3<br>
          <br>
        </div>
        <div># Match all but at start- this puzzles me, 'a' is after the
          start of string but still matches<br>
        </div>
        <div>&gt; 'abcd' ~~ m/&lt;!after ^&gt;.+/<br>
          =EF=BD=A2abcd=EF=BD=A3<br>
          <br>
        </div>
        <div># This is a workaround<br>
          &gt; 'abcd' ~~ m/&lt;!before ^&gt;.+/<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&lt;1&gt; p 'abcd' =3D~ /(.+(?!$))/<br>
          abc<br>
          =C2=A0 DB&lt;2&gt; p 'abcd' =3D~ /((?&lt;!^).*)/<br>
          bcd<br>
          <br clear=3D"all">
          <div>
            <div class=3D"gmail_signature">-y<br>
            </div>
          </div>
        </div>
      </div>
    </blockquote>
    <br>
  </body>
</html>

--------------5B4ACBDF8F79BD3A8250EF63--