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

Help with | in regex...

Thread Next
From:
Paul Farley
Date:
February 26, 2002 06:45
Subject:
Help with | in regex...
Message ID:
20020226144501.20739.qmail@onion.perl.org
I'm trying to use a regex to match a passed value.  I'm trying to use an or
between the patterns, and it needs to be case insensitive.
I've tried it two ways, and it doesn't seem to work either way completely.

1st example:

if($ep =~ /^rglyc[12345] |^rglyd[235678] | ^rglyf3 | ^rglyg6 | ^rglyt5 |
^rglyu1/i)
    {
       $org="LYX";
    subscription($ep,$pr,$sub,$org,$plat);
    }
   elsif ($ep =~ /^rglyv[34567] | ^rglyw[79]/i )
    {
       $org="LYP";
    subscription($ep,$pr,$sub,$org,$plat);
    }

and:

if($ep =~ /^rglyc[12345]/i |/^rglyd[235678]/i | /^rglyf3/i | /^rglyg6/i |
/^rglyt5/i | /^rglyu1/i)
    {
       $org="WRALC.LYX";
    subscription($ep,$pr,$sub,$org,$plat);
    }
   elsif ($ep =~ /^rglyv[34567]/i | /^rglyw[79]/i )
    {
       $org="WRALC.LYP";
    subscription($ep,$pr,$sub,$org,$plat);
    }

Two questions:

1. How do I do an "or" in a regex if statement like this?
2. Is there a better(more efficient) way to do this? (I know that's a loaded
question to a perl list. <G>)

-Paul



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