3 messages in net.sourceforge.lists.courier-maildrop[maildropl] Re: Non greedy matches ?
FromSent OnAttachments
dushyAug 6, 2005 5:43 am 
Sam VarshavchikAug 6, 2005 7:17 am 
Paul L. AllenAug 9, 2005 12:15 pm 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:[maildropl] Re: Non greedy matches ?Actions...
From:Paul L. Allen (pl@softflare.com)
Date:Aug 9, 2005 12:15:53 pm
List:net.sourceforge.lists.courier-maildrop

dushy writes:

Is there a way to do non greedy matches.

I see that Mr Sam has already answered that this is not possible. You can take that as definitive, since he wrote maildrop. And since he did not say "but this is planned for a future release of maildrop" you can bet everything you own that it won't be implemented in the immediate future.

Is there any way to use non greedy quantifiers ?

Back before Perl had non-greedy quantifiers there were ways of dealing with most requirements. There are some things that can only be done with non-greedy quantifiers, and some things that can only be done with later Perl 5.x regexp extensions, but you may be able to find a solution to your requirements using the older techniques (and they may actually be more efficient, although they're equally likely to be less efficient).

Most of the uses of greedy identifiers are of the form

/^(.*?)[x]/

meaning "match as much as you can up until the first occurence of x". But the old way of doing the same thing was

/^[^x]*x/

meaning "match as much as you can that isn't x" and is followed by x.

I didn't read your original post and wouldn't (at this time of night) try to analyse your requirements if I had. But there are workarounds for most sensible requirements that you might think require non-greedy matches. I'm not saying that your requirements aren't sensible, just that it's highly likely you can achieve the same objective without non-greedy matches.

In most cases, unless you're doing something very weird, there's unlikely to be a major performance hit whichever way you did it (if both ways are available). In some cases when you're doing very weird things you need to know whether the underlying regexp engine is a DFA or an NFA in order to determine if your regexp will be efficient or will not complete before the universe dies of increasing entrophy.

I can recommend Jeffrey Friedl's "Mastering Regular Expressions" for a discussion of the relative merits of DFAs and NFAs (and hybrids) and the likelihood that the universe will die before you get a result, but without expending far more effort than I care to at this time of night I cannot tell you which of those schemes is used by maildrop. If you can make it work and it doesn't kill your server with the load then you probably have a reasonably sensible solution, barring pathological cases.