in reply to Re: question about the star(*) quantifier
in thread question about the star(*) quantifier

You would see similar behavior if you try this:
my $sentence = "I fear that i will be extinct after 1000 or 2000 years +"; if($sentence =~ /(\d+)/) { print "That said '$1' years.\n"; }
Since Perl is stopping at the first successful match, you'll only get the first number. Since the empty string is a successful match for \d*, that's what you're getting :)

Replies are listed 'Best First'.
Re^3: question about the star(*) quantifier
by samtregar (Abbot) on Dec 21, 2006 at 17:42 UTC
    Untrue! Please try it and I think you'll see that 1000 is indeed matched. Perl's + modifer is greedy, meaning it will match as much as it can. Perl also takes the first match it can find, which is why the first one stopped at the start of the string. (Or perhaps you meant "1000" by the "first number". I took it to mean "1" which some regex engines might yield.)

    -sam