Alex has asked for the wisdom of the Perl Monks concerning the following question:
I'm a newbie, and feel this question isn't 'worthy' of your attention, but I'm curious as to why this behavior is as such. I do plan to check the perldocs tomorrow, but I'd like to know your thoughts as well. Here's the problem..
my $ua = $ENV{'HTTP_USER_AGENT'};
Using browser Netscape Navigator 6.2 the string returned is this:
Mozilla/5.0 (Windows; U; Win98; en-US; rv:0.9.4) Gecko/20011019 Netscape6/6.2
The problem is if I use this code:
my $ua_name = $1 if ($ua=~ m/(opera|netscape|gecko|msie)/i);
I get this:
$ua_name: Gecko
Even though netscape is delcared before gecko in my regular expression, BUT if I use this:
my $ua_name = $1 if ( ($ua=~ m/(opera)/i) || ($ua=~ m/(netscape)/i) || ($ua=~ m/(gecko)/i) || ($ua=~ m/(msie)/i) );
I will get this:
$ua_name: Netscape
obviously in my first example it didn't matter what order I put the search patterns between the or operator, I thought it would matter. Can anyone confirm this, or did I already do that?
Alex2003-06-07 edit ybiC: retitle from "Simple Question for monks, but I'm curious..."
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: String order in regex match - left to right, or right to left?
by Enlil (Parson) on Jun 07, 2003 at 01:27 UTC | |
by Zero_Flop (Pilgrim) on Jun 07, 2003 at 02:56 UTC | |
by kelan (Deacon) on Jun 07, 2003 at 03:49 UTC | |
by Zero_Flop (Pilgrim) on Jun 07, 2003 at 05:37 UTC | |
by Alex (Initiate) on Jun 08, 2003 at 21:55 UTC | |
by fglock (Vicar) on Jun 07, 2003 at 03:47 UTC |