Skip to content

Instantly share code, notes, and snippets.

@mitchty
Created November 28, 2011 22:42
Show Gist options
  • Save mitchty/1402423 to your computer and use it in GitHub Desktop.
Save mitchty/1402423 to your computer and use it in GitHub Desktop.
Confused on positive lookahead in this case
my $var = "anchor1 lkajfdlkj
match
till
the
next
anchor2
more
stuff
anchor3
blah
till
eof/eol
";
$var =~ /anchor1.*(?=anchor2)/ms;
print $& . "\n";
print "---\n";
$var =~ /anchor1.*(?=anchor)/ms;
print $& . "\n";
# I'm curious why the first match of "anchor" isn't matching anchor2 in the look-ahead. I have to be missing something obvious.
# anchor1 lkajfdlkj
# match
# till
# the
# next
#
# ---
# anchor1 lkajfdlkj
# match
# till
# the
# next
# anchor2
# more
# stuff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment