Hello monks

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?

Alex

2003-06-07 edit ybiC: retitle from "Simple Question for monks, but I'm curious..."


In reply to String order in regex match - left to right, or right to left? by Alex

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.