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

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

Thread Previous | Thread Next
Deven T. Corzine
December 15, 2000 11:50
Re: Perl 5's "non-greedy" matching can be TOO greedy!
Message ID:

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.


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About