develooper Front page | perl.beginners | Postings from March 2002

Regex peculiarity

Thread Next
From:
David Gray
Date:
March 21, 2002 12:59
Subject:
Regex peculiarity
Message ID:
000e01c1d11b$17b93360$7800a8c0@3b2.com
I'm matching a list of 4 measurments (i.e. 4pc,4pc,4pc,4pc) that all
have to have some sort of unit specification (i.e. 4pc6,4in,4px,4pt) and
I'm running into a bit of an oddity...

If I use the regular expression:

/^(?:\d+\w+\d*,?){4}$/

to match the above sequence, it matches the string '10,10,10,10' or any
sequence of 4 2-digit numbers separated by commas, but not one-digit
numbers... The only thing I can think of is that the \w is matching the
commas somehow, but that doesn't make any sense...

I've been staring at this for too long, and it works the way I want it
to if I use:

/^(?:\d+\w{2}\d*,?)$/

instead, but I can't figure out what I'm doing wrong in the other
regex... Anyone have any ideas?

 -dave



Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About