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

Re: Is negative lookbehind behaving here?

Thread Previous
Timo Paulssen
May 4, 2018 16:50
Re: Is negative lookbehind behaving here?
Message ID:
Yes, you've encountered a bug. It's got these two tickets:

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 Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About