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:
brian d foy
Date:
December 16, 2000 11:04
Subject:
Re: Perl 5's "non-greedy" matching can be TOO greedy!
Message ID:
Pine.SOL.3.96.1001216134945.22599E-100000@staging.sri.net
On Fri, 15 Dec 2000, Deven T. Corzine wrote:

> On 15 Dec 2000, Randal L. Schwartz wrote:
> 
> > >>>>> "Deven" == Deven T Corzine <deven@ties.org> writes:
> > 
> > Deven> As for special-case rules, I believe that my proposed modification would
> > Deven> REMOVE a special-case semantic rule, at the cost of added complexity at the
> > Deven> implementation level.  (The cost decision of whether that added complexity
> > Deven> is worthwhile is a separate consideration.)

> > No, it would break a much higher overriding rule of "left most match
> > wins". 
> 
> Can you give a concrete, real-life example of code that my proposed change
> would actually break, not a contrived hypothetical case design to break?

well, there is the trivial case that it breaks

	m/b.*d/;

if i wrote that, i expect, since it is documented this way, to find the
first b and everything up to and including the first d after that.


but here's one from some code i wrote last week.  i want to find all the
groups of things like "212-555-1212".  this particular regex adequately
describes the un-normalized data that i had to munge. 

	@matches = m/(\d.*?)\s+/g;

the right way (the documented way), gives me the entire phone number.
yours give me "2".

you should be quiet now, or write your own language.


--
brian d foy                              <brian@smithrenaud.com>
Director of Technology, Smith Renaud, Inc.
875 Avenue of the Americas, 2510, New York, NY  10001
	V: (212) 239-8985


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