in reply to
Using Look-ahead and Look-behind
Thank you for your very nice article, I certainly learned some new tricks!
Just one little comment: The code in the last paragraph did not work because by default regular expressions are greedy. (Did this change with the Perl versions in between?) The only right-substring that comes out is the full string:
$_ = "Hello";
print "$1\n" while /(?=(.*))/g;
Output:
Hello
Making the "(.*)" part non-greedy fixes it (in Perl 5.10):
$_ = "Hello";
print "$1\n" while /(?=(.*)?)/g;
Output:
Hello
ello
llo
lo
o