On 7/11/2004 1:07 AM, Gunnar Hjalmarsson wrote:
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

With

      /(\w+)\s+(-?\d+.\d+)\s+(-?\d+.\d+)\s+(-?\d+.\d+)\s+(\w+)/;

What am I doing wrong?


You are not showing us a complete program that generates some other output than the output you were expecting.

A couple of observations besides that:

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


Better yet, use Regexp::Common:

use Regexp::Common qw(number);
/(\w+)(?:\s+$RE{num}{real}){3,3}\s+(\w+)/;


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