On Jul 11, Jeff 'japhy' Pinyan said:

>I tend to write that as /(-?\d+\.?\d*)/, but be aware that this doesn't
>match numbers like .52 or .9, because they don't have digits BEFORE the
>decimal point.

I've seen the response of /-?(?:\d+\.?\d*|\.\d+)/, and while that does
work, it seems too noisy to me.  What we would really like to be able to
say is /-?\d*\.?\d*/, but you should be able to see that could match "-."
and "." and "", which we decided aren't legitimite numbers.

So use a look-ahead.

  /(-?(?=.?\d)\d*\.?\d*)/

*That* regex requires some explanation.  Who will give it?

-- 
Jeff "japhy" Pinyan         %  How can we ever be the sold short or
RPI Acacia Brother #734     %  the cheated, we who for every service
http://japhy.perlmonk.org/  %  have long ago been overpaid?
http://www.perlmonks.org/   %    -- Meister Eckhart


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to