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

Thanks for all your quick replys, but i still have a question.

The pattern /(\d*)/'s first match should be a number, right? instead of the zero length string. In my case, it should find character '1' first and assign value '1' to $1.

Please advice. :)

  • Comment on Re^2: question about the star(*) quantifier

Replies are listed 'Best First'.
Re^3: question about the star(*) quantifier
by samtregar (Abbot) on Dec 21, 2006 at 17:49 UTC
    Nope. \d* means "zero or more numbers" not "one or more numbers". It is perfectly valid for \d* to match the empty string, which is "zero numbers". If you want to be sure to match a number, use \d+, which means "one or more numbers".

    -sam

Re^3: question about the star(*) quantifier
by chargrill (Parson) on Dec 21, 2006 at 17:52 UTC

    It's already been said above, but I'll restate it:

    \d* means explicitly: "Match 0 or more digits"

    That matches any sequence of characters that is "0 or more digits".

    At the very beginning of your string (leftmost portion), a string matches that - an empty string '' right before "I fear that...".

    Update: I guess samtregar beat me to it, but our message is the same :)



    --chargrill
    s**lil*; $*=join'',sort split q**; s;.*;grr; &&s+(.(.)).+$2$1+; $; = qq-$_-;s,.*,ahc,;$,.=chop for split q,,,reverse;print for($,,$;,$*,$/)

      I see now.

      Thanks for all your answers and good explainations.

      Thanks again.

      Cindy