procmail
[Top] [All Lists]

Re: Please dont laugh at my recipe, help needed

1998-12-17 12:12:15
Excerpts from mail: (17-Dec-98) Please dont laugh at my recipe, help needed by 
Todd Lindstrom
I have a rather cumbersome recipe that I know is very very
poor in its construction.  I'd like to know what kind of
shortcut I can do to make it a better regular expression.

Well, the first thing I would suggest when trying to optimize regular
expressions is to find characters that are repeated in each subexpression and
combine them. First off, you can move the caret ("^") from inside each
subexpression to in front of the outermost set of parentheses. Secondly, you
can combine all the From: subexpressions and all the Reply-To:
subexpressions. Also, I'm going to put a backslash in front of all your
period characters that are meant to match only periods.

* ^((From:.*(virtual\.co\.il|yafbatya|BonusMail|alesis1|discgolfer|\
             wildershow|onelist\.com|discsports|316csi\.com))|\
    (Reply-To:.*(stretcher\.com|shabbatshalom))|\
    (Errors-To:.*netcenter-news))

Some additional optimizations could be done here. For example, "disc" is
repeated in two of the "From:" subexpressions. Also, ".com" is repeated in
two of the subexpressions as well. If we shuffle the subexpressions around,
we can combine those as well. That's a pretty minor optimization and it may
not worth the decrease in readability and maintainability for you, but, to be
pedantic, I will show how anyway.

* ^((From:.*(virtual\.co\.il|yafbatya|BonusMail|alesis1|wildershow|\
             disc(golfer|sports)|\
             (onelist|316csi)\.com))|\
    (Reply-To:.*(stretcher\.com|shabbatshalom))|\
    (Errors-To:.*netcenter-news))

Hope this helps,
Ed

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