[Mailman-Users] Help with regular expression filters

Mark Sapiro mark at msapiro.net
Tue Feb 3 22:43:09 CET 2015

On 02/03/2015 12:08 PM, e.c. wrote:
> At least in Emacs the following regexp works
> \_<test\_>
> that finds 'test' but not 'fastest' or 'testy'
> bash, perl, ruby, etc. may have different ways of doing the same thing.

In Mailman, with Python regexps
<https://docs.python.org/2/library/re.html>, I would use


\W matches any 'non-word' character and is equivalent to [^a-zA-Z0-9_],
i.e. anything including new-line which is not a letter, digit or underscore.

>>> import re
>>> cre = re.compile('^Subject:.*\Wtest\W', re.IGNORECASE)
>>> s1 = """Subject: This is a test of mailman."""
>>> s2 = """Subject: This is a test."""
>>> s3 = """Subject: I am testing..."""
>>> s4 = """Subject: This is a test
... """
>>> cre.search(s1)
<_sre.SRE_Match object at 0x7f740d0abac0>
>>> cre.search(s2)
<_sre.SRE_Match object at 0x7f740d0abb28>
>>> cre.search(s3)
>>> cre.search(s4)
<_sre.SRE_Match object at 0x7f740d0abac0>

Mark Sapiro <mark at msapiro.net>        The highway is for gamblers,
San Francisco Bay Area, California    better use your sense - B. Dylan

More information about the Mailman-Users mailing list