Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Re: Re: This looks like someone sneezed and hit the keyboard

by bunnyman (Hermit)
on Feb 03, 2004 at 16:33 UTC ( [id://326228]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: This looks like someone sneezed and hit the keyboard
in thread This looks like someone sneezed and hit the keyboard

No, everything in the regex must match, not just the first part of it, and the part in the middle with the (one|two|three) must match too.

The thing that you must remember is that regexes can backtrack -- if they get to the end of the string without having matched yet, they can go back a few letters and try again.

So the .* part will first try to match the entire string, because it is greedy. Then the middle part (one|two|three) must match, but there is nothing left in the string, and we must backtrack and try again. First we try going one letter back, then two, and eventually we either find the match or we backtrack all the way to the start and then there is no match.

  • Comment on Re: Re: Re: This looks like someone sneezed and hit the keyboard

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2024-06-14 11:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.