Why doesn't this look-behind assertion work when it's anchored to the front of the string? Run the following code and you'll see that the first test passes but the second, which varies only by the ^
anchor, fails.
use Test::More tests => 2;
my $s = '/123/456/hello';
$s =~ s{(?<=/)\d+(?=/\d+/hello)}{0}; # unanchored
is($s, '/0/456/hello', 'unanchored'); # passes
$s = '/123/456/hello';
$s =~ s{^(?<=/)\d+(?=/\d+/hello)}{0}; # anchored
is($s, '/0/456/hello', 'anchored'); # fails
Moving the ^
into the look-behind assertion isn't an option for me (this is an extremely simplified example) but that does fix the problem. I've found an alternate way to do what I want, but I'm curious why this approach didn't work. I've tested this on perl 5.8.8 and perl 5.10.0.