[Top] [All Lists]

Re: Using variables in regular expressions in recipes

2007-01-05 19:37:46
Sorry, Geoff, I'm too tired to explain all the reasons, but you have 
five mistakes in here:

EXCEPTION = "option1|option2|option3"

* !^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.


  EXCEPTION = 'option1|option2|option3'

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

procmail mailing list   Procmail homepage:

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