develooper Front page | perl.perl6.language | Postings from May 2018

Re: Is negative lookbehind behaving here?

Thread Previous
From:
Timo Paulssen
Date:
May 4, 2018 16:50
Subject:
Re: Is negative lookbehind behaving here?
Message ID:
64514678-d61b-9ad3-a060-57b8ad3584ab@wakelift.de
Yes, you've encountered a bug. It's got these two tickets:

https://rt.perl.org/Public/Bug/Display.html?id=124898
https://rt.perl.org/Public/Bug/Display.html?id=131964

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!
  - 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 $>/
> 「abc」
>
> # Match all but at start- this puzzles me, 'a' is after the start of
> string but still matches
> > 'abcd' ~~ m/<!after ^>.+/
> 「abcd」
>
> # This is a workaround
> > 'abcd' ~~ m/<!before ^>.+/
> 「bcd」
>
> Using a perl5 debugger session, roughly translated negative
> lookbehind/lookahead work as I expect.
>
>   DB<1> p 'abcd' =~ /(.+(?!$))/
> abc
>   DB<2> p 'abcd' =~ /((?<!^).*)/
> bcd
>
> -y


Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About