Nik has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

How can i say in a regexp that if $host contains thes530-xxxx.otenet.gr or $host contains millennium-xxxx.ccf.auth.gr then blablabla

where x = whatever character.....

Replies are listed 'Best First'.
Re: regeex question
by Roger (Parson) on Feb 29, 2004 at 22:51 UTC
    if ($host =~ /thes530-.*?\.otenet\.gr|millennium-.*?\.ccf\.auth\.gr/) +{ # blah blah ...
Re: regeex question
by dragonchild (Archbishop) on Mar 01, 2004 at 02:44 UTC
    Roger's answer is correct. I would go further and say you probably want to construct this regex programmatically.
    my $thes530 = qr/thes530-....\.otenet\.gr/; my $millenium = qr/millennium-....\.ccf\.auth\.gr/; my $regex = qr/$thes530|$millenium/; if ($host =~ /$regex/) { print "Yay!\n"; }

    I'm sure there's a way to join qr's, but I've never tried it.

    ------
    We are the carpenters and bricklayers of the Information Age.

    Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

Re: regeex question
by neniro (Priest) on Feb 29, 2004 at 23:16 UTC
    Hello Nik,
    if the characters you x'ed out are useful for you, you can extract them in the match if you use parenthesis:
    if ($host=~m/thes530-(\w+)\.otenet\.gr/) { my $info = $1; }
    I forgot, you have to escape the "." or it matches any character.
Re: regeex question
by Wonko the sane (Curate) on Feb 29, 2004 at 22:52 UTC
    Hello,

    Seems to be a very basic question, am I missing something?

    if ( $host =~ /thes530-xxxx.otenet.gr|millennium-xxxx.ccf.auth.gr/ ) { # blahblahblah... }
    Update: Ah I see what you meant. Roger's solution is prob what you want.