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
Jeff Pinyan
December 14, 2000 14:54
Re: Perl 5's "non-greedy" matching can be TOO greedy!
Message ID:
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).



is what I'd meant to say.

I wouldn't call the current behavior a design flaw, though.

Jeff "japhy" Pinyan
CPAN - #1 Perl Resource  (my id:  PINYAN)
PerlMonks - An Online Perl Community
The Perl Archive - Articles, Forums, etc.

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About