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:33
Subject:
Re: Perl 5's "non-greedy" matching can be TOO greedy!
Message ID:
Pine.LNX.4.10.10012151425260.31056-100000@escher.ties.org

On 14 Dec 2000, Randal L. Schwartz wrote:

> >>>>> "Deven" == Deven T Corzine <deven@ties.org> writes:
> 
> Deven> I haven't even SEEN an example where the current behavior is
> Deven> actually preferable than my proposed behavior, have you?  (And
> Deven> I'd expect at least a FEW, though I suspect there are probably
> Deven> more counterexamples.)
> 
> If I want the leftmost B that is followed by the shortest number
> of characters to get to a D, I write /B.*?D/.  The "leftmost" part
> keeps getting left out of regex discussions, and maybe that's why
> you're thrown off.  But it's a pretty consistent overriding factor.

That's not an example, that's a hypothetical.  I meant that I've never seen
a concrete, realistic example where the current behavior is more beneficial
to the programmer than my proposed behavior.  (I imagine in most cases, it
will be a moot point, since the match will usually be the same.)

> If you want something odd like "not necessarily the leftmost", then
> you'll need to speak more.  But "leftmost" is fundamental to the
> design of regex.  Don't mess with that.  Or don't call it a regex any
> more.

Strange argument.  Greedy matching was once considered fundamental to the
design of regex, and the "leftmost" behavior is 100% consistent with greedy
matching.  Yet Perl 5 added non-greedy modifiers, changing a fundamental
aspect of every preceding regex system, and still called it a regex...

Extending the design of the regex system to allow for non-greedy matching
was an excellent extension, and made Perl 5's regular expressions far more
powerful than anyone else's.  But they're certainly different than before.

I wish I had been involved in the discussions when the idea of non-greedy
matching was proposed and the details ironed out.  I don't think my ideas
would have had the same kind of concerted opposition back then as now...

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