develooper Front page | perl.perl5.porters | Postings from August 2000

Re: Proposal for \v and \V, the small- and large- cut regex operators.

From:
Nick Ing-Simmons
Date:
August 9, 2000 14:41
Subject:
Re: Proposal for \v and \V, the small- and large- cut regex operators.
Message ID:
E13MdS1-0001La-00@roam1
Simon Cozens <simon@brecon.co.uk> writes:
>
>>From a user's point of view, I find the "Combining Pieces Model" a much,
>much, much more straightforward explanation. Let's take one of the
>examples in perlre:
>
>           $_ =  "The food is under the bar in the barn.";
>           if ( /foo(.*)bar/ ) {
>
>Now, the backtracking explanation says we find foo, then the rest of the
>string, then back up steadily until we get to a "bar". The combining
>pieces model says: we have three parts. We match "foo", then as much as
>possible of everything provided it is followed by "bar". 
>
>You'll note that while the backtracking explanation gives us a clear
>picture of how the regular expression is executed by Perl, the combining
>pieces model is far more useful when it comes to actually *writing*
>regular expressions. When you're thinking about how *you*, as a human
>being, would look for the match in the string, you don't think about
>going all the way to the end of the string and then backing up. 

>You look
>for three distinct chunks - "foo", lots of stuff, "bar" - and so when
>you're programming, you state three distinct chunks. 

I can imagine implementing it like that too - look for 'foo', starting from 
there look for next literal, now does the stuff in between match the 
complex thingy?  One would start from end of string if 'thingy' was .*
and just past foo if it was '.*?'.


-- 
Nick Ing-Simmons




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About