Re: Perl 5's "non-greedy" matching can be TOO greedy!
[email protected] ("Deven T. Corzine") Fri, 15 Dec 2000 14:50:21 -0500 (EST)
| Newsgroups | perl.perl6.language.regex |
|---|---|
| Message-ID | <[email protected]> |
On Thu, 14 Dec 2000, Jeff Pinyan wrote: > You could use my sexeger technique to get this behavior (possibly): > > $string = "aaabbbcccdddeee"; > # regex to be reversed: /b(.*?)d/ > $revstr = reverse $string; > ($match) = $revstr =~ /d(.*?)b/; > > No, that doesn't quite work. It works when you unroll the .*? loop: > > # regex to be reversed: /b([^bd]*)d/ > ($match) = $revstr =~ /d([^bd]*)b/; > > But then why would you use sexeger at all, when you can unroll the loop in > the forward direction? > > ($match) = $string =~ /b([^bd]*)d/; I'm not asking for help with workarounds. If I ever need to workaround the current behavior, I won't have any trouble doing so. It's just that (on a philosophical note) I don't believe this is something that should require a workaround. Obviously, others disagree. Deven