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

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

From:
brian d foy
Date:
December 16, 2000 11:18
Subject:
Re: Perl 5's "non-greedy" matching can be TOO greedy!
Message ID:
Pine.SOL.3.96.1001216140948.22599F-100000@staging.sri.net
On Fri, 15 Dec 2000, Deven T. Corzine wrote:

> If we want the first interesting match, and we're preferring early matches
> and short matches, I believe that "bccccd" is more interesting.

then write a regex that describes that pattern.  the pattern is

	one b
		followed by
	some stuff that is not a d
		up to
	one d

you complain because the "." regex special character does not do what you
want.  it matches any character except a newline.  however, for the case
you provide, you don't want any character except a newline. so, your use
of "." is your problem, along with your refusal to realize that what you
are dealing with is a set of rules, and if you grok the rules, you can do
what you want.  it has nothing to do with opinion or intuition.  neither
of those have any place in a completely (well, almost ;)  described,
human-designed system. this isn't nuclear physics after all. 

your trouble is not with greediness or shortest matches, as i said before.
you just don't understand what you are doing and refuse to beleive
otherwise. 

--
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





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