develooper Front page | perl.perl6.language.regex | Postings from December 2000

Re: Perl 5's "non-greedy" matching can be TOO greedy!

From:
Deven T. Corzine
Date:
December 15, 2000 11:50
Subject:
Re: Perl 5's "non-greedy" matching can be TOO greedy!
Message ID:
Pine.LNX.4.10.10012151448540.31056-100000@escher.ties.org

On Thu, 14 Dec 2000, Jeff Pinyan wrote:

> You could use my sexeger technique to get this behavior (possibly):
> 
>   $string = "aaabbbcccdddeee";
>   # regex to be reversed: /b(.*?)d/
>   $revstr = reverse $string;
>   ($match) = $revstr =~ /d(.*?)b/;
> 
> No, that doesn't quite work.  It works when you unroll the .*? loop:
> 
>   # regex to be reversed: /b([^bd]*)d/
>   ($match) = $revstr =~ /d([^bd]*)b/;
> 
> But then why would you use sexeger at all, when you can unroll the loop in
> the forward direction?
> 
>   ($match) = $string =~ /b([^bd]*)d/;

I'm not asking for help with workarounds.  If I ever need to workaround the
current behavior, I won't have any trouble doing so.  It's just that (on a
philosophical note) I don't believe this is something that should require a
workaround.  Obviously, others disagree.

Deven




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