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

Is negative lookbehind behaving here?

Thread Next
From:
yary
Date:
May 4, 2018 05:39
Subject:
Is negative lookbehind behaving here?
Message ID:
CAG2CFAbYp9AKP6zQ+qpWxt5xL5F9_kaeFwqUEN9D7gFMnWuRDg@mail.gmail.com
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 Next


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