Matching on Regular Expressions

| - Either/Or
Let's say we want to filter any mail from root@ux4 or root@ux5 or root@ux7. We could write three recipies or we could use a regular expression that matches all there.
# This will match mail from root@ux4 or root@ux5 or root@ux7. It saves a copy in my
# "important" folder and continues so it also shows up in my inbox.

:0c
* ^From: root@(ux4|ux5|ux7)
important
This could also be written as
:0c
* ^From: root@ux(4|5|7)
important
.* - Zero of more characters of any kind
Let's say some bonehead is sending us annoying mail and we want to delete it no matter what machine they mail it from. We know they always use the "jgross" login but they tend to send it from lots of different machines. The From: also tends to be "From: Joe Gross <jgross@stimpy.net>" so matching just on jgross won't work.

We could use the ".*" character wild card. This is actually two regular expression characters but tend to be used as one so we won't worry about it for now.

# this will match on mail from jgross@ any machine and toss it into /dev/null
# note the space after .* but not before. this is so it will also match
# on "From: jgross@stimpy.net" but won't match on "From: mjgross@other.net".

:0
* ^From:.* jgross@.*
/dev/null
There are a lot of other regular expression but these are the most important for procmail. Pick up a perl book for good coverage of all the egrep regular expressions.


Back: Recipe flags Top Next: More complex filtering

j g r o s s @ s t i m p y . n e t