I expected this to print "[b]", but it will print "[]":
$x = "abc";
$x =~ /(b*)/;
print "[$1]";
If a star is replaced by a plus, it acts as I expect. Shouldn't both the pluses and the stars be greedy?
ADDED: Thanks to everyone for pointing out (in seconds, it seemed!) That "b *" matches an empty line, the first occurrence of which precedes the beginning of the line. So greed is not a problem. It matches the empty string, even before the first "b".
source
share