If I run
"Year 2010" =~ /([0-4]*)/;
print $1;
I get empty string. But
"Year 2010" =~ /([0-4]+)/;
print $1;
outputs "2010". Why?
See Question&Answers more detail:osIf I run
"Year 2010" =~ /([0-4]*)/;
print $1;
I get empty string. But
"Year 2010" =~ /([0-4]+)/;
print $1;
outputs "2010". Why?
See Question&Answers more detail:osYou get an empty match right at the start of the string "Year 2010" for the first form because the * will immediately match 0 digits. The + form will have to wait until it sees at least one digit before it matches.
Presumably if you can go through all the matches of the first form, you'll eventually find 2010... but probably only after it finds another empty match before the 'e', then before the 'a' etc.