On Jul 11, Gunnar Hjalmarsson said:

>Jerry Preston wrote:
>> I am trying to setup a single regex to breakdown the following lines:
>>
>> Jerry        2.7    4      4.5          mon
>> Mark -14    -10.75 -10          new
>>
>>       /(\w+)\s+(-?\d+.\d+)\s+(-?\d+.\d+)\s+(-?\d+.\d+)\s+(\w+)/;
>
>You are not showing us a complete program that generates some other
>output than the output you were expecting.

But we can see that his text does NOT match his regex.

>- Not all numbers at those lines include digits before and after a
>decimal point.
>
>- The '.' character has a special meaning when used in a regex outside
>a character class, and should therefore be escaped.
>
>This code:
>
>     (-?\d+(?:\.\d+)?)
>
>would match any of those numbers.

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.

-- 
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