Given this string:
   my $str = "Romp romp ROMP";

We can match just the first or last by using the usual pinning
features, '^' or '$':

   say $str ~~ m:i:g/^romp/;               ## (「Romp」)
   say $str ~~ m:i:g/romp$/;               ## (「ROMP」)

Moritz Lenz (Section 3.8 of 'Parsing', p32) makes the point you
can use 'after' to do something like '^' pinning:

   say $str ~~ m:i:g/ <!after .> romp /;   ## (「Romp」)

That makes sense:  the BOL is "not after any character"
So: I wondered if there was a way to use 'before' to do
something like '$' pinning:

  say $str ~~ m:i:g/ romp <!before .> /;  ## (「Romp」 「romp」)

That was unexpected: it filters out the one I was trying to
match for, though the logic seemed reasonable: the EOL is "not
before any character".

What if we flip this and do a positive before match?

  say $str ~~ m:i:g/ romp <?before .> /;  ## (「Romp」 「romp」)

That does exactly the same thing, but here the logic makes
sense to me: the first two are "before some character",
but the last one isn't.

Reply via email to