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
From:
Deven T. Corzine
Date:
December 15, 2000 11:54
Subject:
Re: Perl 5's "non-greedy" matching can be TOO greedy!
Message ID:
Pine.LNX.4.10.10012151450530.31056-100000@escher.ties.org

On Thu, 14 Dec 2000, James Mastros wrote:

> On Thu, Dec 14, 2000 at 04:10:12PM -0500, Deven T. Corzine wrote:
> > The crux of the problem is that non-greedy qualifiers don't affect the
> > "earliest match" behavior, which makes the matches more greedy than they
> > really ought to be.
> Right.  We've got a terminoligy issue.  There's two axes here:

Not the only terminology issue, but I've addressed that in other messages.

> Greed: Greedy by default.  Will try to match as many chars after its
> starting point as possible.  Non-greedy will try to match as few chars after
> its starting point as possible, and is denoted by putting a '?' after a
> quantifer.
> 
> Lazyness: Eager by default.  An eager assertation will try to match as early
> as possible.  It isn't possible to use lazy assertations at present.  (Not
> simply, anyway.  It's probably possible to combine other (?) features to get
> the same effect.)
> 
> You seem to want the choice between greedy, eager assertations, and
> non-greedy, lazy assertations.  If you came up with a good way to specify
> along both axes, I think we'd have a winner.

I want the maximum level of OVERALL consistency for regular expressions as
a whole, rather than immutable adherence to the "leftmost trumps nongreedy"
rule currently in place.  Most of the time, I agree with the precedence of
leftmost over nongreedy.  The example I gave is a case where I believe the
strict adherence to the leftmost rule actually introduces complexity and
makes the regular expression system less self-consistent.

I don't know if anyone else will ever believe me or not.

Deven



Thread Previous | Thread Next


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