in reply to Regex trouble

It appears that you just forgot a ? after the second "half" of the regex. That's why it would match with two numbers but not with one.

Here's how I modified it:

my $R = 'dounut_s12x30'; print "$1, $2\n" if $R !~ /^i|^ddi/ and $R =~ /^[a-z_]+(\d+\.?\d*)[a-z_]?(\d+\.?\d*)? +/;
Outputs:
12, 30

Is this what you are asking?

Russ

Replies are listed 'Best First'.
RE: RE: Regex trouble
by cyclone (Novice) on May 17, 2000 at 00:33 UTC
    Hey Russ,
    That's close but I have to be able to match "r10" , "r10.5" , "rect20x50" or "rect20.5x50.5".
    And in reality I the word char part of the string can be almost anything. And there may or may not be a second set of number chars. That's why I left the trailing "?" off of the regex.
      Hmmm,

      The trailing ? is what allows you to have (or not have) a second set of numbers.

      This regex works for all sample strings you provided. Feel free to post more information, and I'll help you however I can.

      Russ

        Yes of course. I don't know what I was thinking... I musta had it confused with a trailing '$'. Thanks.