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

Replies are listed 'Best First'.
Re: regex question
by rob_au (Abbot) on May 22, 2002 at 04:54 UTC
    You need to use the pipe symbol (|) within the regular expression for alternation (OR) matching - See perlman:perlre for details.

    if ($form{'webcam'} =~ /http|www/i)

    You'll also note that I have added the i option to the match to perform case-insensitive matching - This allows your regular expression to match these terms within your hash, irrespective of the string case. Again, read about this in perlman:perlre.

     

Re: regex question
by Flame (Deacon) on May 22, 2002 at 05:02 UTC
    If you don't mind the added complexity and extra features you probably don't need, you should take a look at URI



    "Weird things happen, get used to it."

    Flame ~ Lead Programmer: GMS

Re: how to use alternation in a regular expression
by abstracts (Hermit) on May 22, 2002 at 05:55 UTC
    if ($form{webcam} =~ (/http/ OR /www/) AND (/jpg/ OR /gif/))
    Maybe you're looking for somthing in the neighborhood of
    if ($form{webcam} =~ /^(http|www).*(jpg|gif)$/){
    But no, that will not ensure that you have an internet address of an image. The only way to ensure that is to actually get what's in that address and check that it's an image. You can guess, but you may be too surprised.

    PS. If you're looking for links in a file, you might want to consider URI::Find which simplifies the task down to writing a callback function.

    Hope this helps,,,