Re: Perl 5's "non-greedy" matching can be TOO greedy!
[email protected] (Jeff Pinyan) Thu, 14 Dec 2000 17:54:46 -0500 (EST)
| Newsgroups | perl.perl6.language.regex |
|---|---|
| Message-ID | <[email protected]> |
On Dec 14, Deven T. Corzine said: >> You're asking for something like >> >> /(?<!b)(b.*?d)/ >> >> which is an "optimization" you'll have to incorporate on your own. > >Thanks for the example. Unfortunately, your attempted workaround doesn't >even work for the example string; the "a" preceding "bbbbccccd" isn't a >"b", so the regexp engine is still perfectly happy with the same match. >Even if it worked as you intended, it would have failed with something like >"bbbabbbccccdddd", since the ".*?" would happily match "bbabbbcccc"... Sorry, I was thinking backwards (when I was supposed to think forwards). Using: /(b(?!b).*?d)/ is what I'd meant to say. I wouldn't call the current behavior a design flaw, though. -- Jeff "japhy" Pinyan [email protected] http://www.pobox.com/~japhy/ CPAN - #1 Perl Resource (my id: PINYAN) http://search.cpan.org/ PerlMonks - An Online Perl Community http://www.perlmonks.com/ The Perl Archive - Articles, Forums, etc. http://www.perlarchive.com/