procmail
[Top] [All Lists]

Re: Using variables in regular expressions in recipes

2007-01-05 19:57:07

David W. Tamkin wrote:
Sorry, Geoff, I'm too tired to explain all the reasons, but you have 
five mistakes in here:

EXCEPTION = "option1|option2|option3"

:0
* !^TO_(_dot_)*${EXCEPTION}(_dot_)*\(_at_)(_dot_)*

First, you're lacking the "$" modifier to tell procmail to do variable 
and command substitution.

Second, the expansion of ^TO_ ends in something that is almost always 
better than .* for it, adding .* undoes the good, and it's extremely 
unlikely that you want to do that (in rare cases one does, but I've a 
feeling this isn't one of those).

Third, unless you put parentheses into the condition somehow around 
the alternatives, the result won't be what I'm very sure you want.  
You can put them into the definition of the variable

 EXCEPTION = '(option1|option2|option3)'

(and 3 1/2th: it's pretty likely that you're better off with 
apostrophes than quotation marks, but quotation marks don't hurt)

or into the condition itself,

 ($EXCEPTION) # braces not needed, but you can put them in if you like

Fourth (and least), you don't have to escape the at-sign.

Fifth, regular expressions are unanchored by default, unlike shell 
globbing patterns, so unless you are using the \/ extraction operator 
to set MATCH (and you aren't doing that there), a trailing .* is just 
a waste of processing cycles.

So,

 EXCEPTION = 'option1|option2|option3'

:0
* $ ! ^TO_($EXCEPTION).*@

Hi,
your third point regarding the lack of parentheses was down my 
accidentally removing them when composing the mail. Otherwise they were 
all genuine mistakes!

Thanks very much for being so thorough, I now need to go back and 
revisit all my other .procmailrc files as they are evidently full of 
mistakes!!

Thanks again,
Geoff


____________________________________________________________
procmail mailing list   Procmail homepage: http://www.procmail.org/
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail

<Prev in Thread] Current Thread [Next in Thread>