in reply to String order in regex match - left to right, or right to left?
my $ua_name = $1 if ($ua=~ m/(opera|netscape|gecko|msie)/i);
In the second piece of code:
What happens in this is that it will check the whole string and for something (ie. netscape, gecko, etc..) and then move on to the next regex if it fails. I can elaborate if need be.my $ua_name = $1 if ( ($ua=~ m/(opera)/i) || ($ua=~ m/(netscape)/i) || + ($ua=~ m/(gecko)/i) || ($ua=~ m/(msie)/i) );
update: perhaps an example would help better explain how the regex engine is working, at the command line try this one-liner:
Also I struck out the first sentence which was causing confusion, and replaced it with a new first sentence. Thanks Zero Flop for pointing out my poor wording. -enlilperl -Mre=debug -le "$s = 'a man a plan a camel';print $1 if $s =~ /(c +amel|plan|monkey)/;"
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: (2) String order in regex match - left to right, or right to left?
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 |