Both /(?=abc)\b/ and /(?<=abc)\b/ match the string "---abc",
but not at the same position, as the program below shows:
#!/usr/bin/perl
use strict;
use warnings;
$_ = "---abc";
/(?=abc)\b/ and print "Lookahead \$` = '$`'; \$' = '$''\n";
/(?<=abc)\b/ and print "Lookbehind \$` = '$`'; \$' = '$''\n";
__END__
Lookahead $` = '---'; $' = 'abc'
Lookbehind $` = '---abc'; $' = ''
/(?=abc)\b/ matches at a word boundary that is followed
by "abc", hence after "---", but before "abc".
/(?<=abc)\b/ matches at a word boundary that is preceded
by "abc", hence after "abc", and right before the end of
the string.
Abigail | [reply] [d/l] |