Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: (3) String order in regex match - left to right, or right to left?

by kelan (Deacon)
on Jun 07, 2003 at 03:49 UTC ( #263913=note: print w/replies, xml ) Need Help??


in reply to Re: (2) String order in regex match - left to right, or right to left?
in thread String order in regex match - left to right, or right to left?

Gecko comes first in the string that is being searched. When the regex engine is trying to match a regex in a string, it starts at the first character of the string and tries to match from the beginning of the regex. If it can't match at that position, it moves to the next character of the string and starts trying to match again (unless you anchor the regex). In this case, the match keeps failing until it gets to the point in the string where 'Gecko' appears. At that point, the regex engine says to itself: "Can this match 'opera'? No. Can this match 'netscape'? No. Can this match 'gecko'? Yes. Return captured string 'gecko'. Done." Which happens before it gets to the point in the string where 'Netscape' appears.

kelan


Perl6 Grammar Student

  • Comment on Re: (3) String order in regex match - left to right, or right to left?

Replies are listed 'Best First'.
Re: (4) String order in regex match - left to right, or right to left?
by Zero_Flop (Pilgrim) on Jun 07, 2003 at 05:37 UTC
    Thanks for clearing that up!

    So...

    It takes the first word of the string ("Mozilla" in this case) and compares it to each regex, opera then netscape then gecko ...

    This is reversed as to how I interprited it. I guess I think about it backwards, as taking opera and comparing that to each word in the string.
Re: Re: (3) String order in regex match - left to right, or right to left?
by Alex (Initiate) on Jun 08, 2003 at 21:55 UTC
    Kelan

    Thank you very much, that does indeed explain it. I think Enlil tried to explain this to me as well, but I didn't get it. Thank you both for your help!

    Alexander Garcia

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://263913]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2022-12-08 03:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?