Re: Perl 5's "non-greedy" matching can be TOO greedy!
[email protected] (brian d foy) Sat, 16 Dec 2000 14:04:30 -0500 (EST)
| Newsgroups | perl.perl6.language.regex |
|---|---|
| Message-ID | <[email protected]> |
On Fri, 15 Dec 2000, Deven T. Corzine wrote: > On 15 Dec 2000, Randal L. Schwartz wrote: > > > >>>>> "Deven" == Deven T Corzine <[email protected]> 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 <[email protected]> Director of Technology, Smith Renaud, Inc. 875 Avenue of the Americas, 2510, New York, NY 10001 V: (212) 239-8985