IT Connect

Information technology tools and resources at the UW

Regular Expressions in Mailman

Regular Expressions Explained

Regular expressions are used within the Python programming language (which is what Mailman is written in) and other programming languages to specify rules for matching strings of text. In other words, you can use regular expressions to match text in incoming email messages. The settings in which you use the regular expressions will tell Mailman what to do with messages that have matching text.

The settings in Mailman that will accept regular expressions will also accept non-regular expression text so there needs to be a way for Mailman to know whether the text that is entered is a regular expression or not. To specify that the text is a regular expression, begin the line with ^.

Common Uses of Regular Expressions in Mailman

Specify Domains That Are Allowed to Post

The most common use of regular expressions in Mailman is to specify entire domains that can and cannot post messages to your list. For example, to allow all addresses in the domain, even those addresses that are not subscribed, to post messages without moderation to your list, go to Privacy Options and then the Sender filters sub-category and enter the following regular expression in the accept_these_nonmembers setting:


The ^ specifies that the string is a regular expression. The .* specifies that any text that comes before the “” part of the email address of the sender is acceptable. For example,,, and will all match the regular expression. The \ specifies that the subsequent period is part of the text of the string you want to match and not a special character that can be used in regular expressions. The $ specifies that it is the end of the string.

Please be aware that spammers often forge the headers of spam email. If the forged From header is set to an email address ending in, that message will be able to get through to your list. If you are concerned about spam on your list, see the How can I avoid spam on my Mailman list? FAQ.

Specify Domains That Are Not Allowed to Post

To ban an entire domain from being able to post to your list and have Mailman automatically discard all messages from that domain, enter the following regular expression in the discard_these_nonmembers setting on the Privacy Options category → Sender filters subsection of the admin pages:


where “domain” is the domain you want to block.

Ban Non-UW Email Addresses From Subscribing

If you want to ban all non-UW email addresses from subscribing to your list, enter the following regular expression in the ban_list setting on the Privacy Options category → Subscription Rules subsection of the admin pages:


As you can see, this regular expression is a little more complex than the preceding ones. This regular expression is known as a negative lookahead and is telling Mailman to match subscribing email addresses that don’t end in “” and to ban those matching email addresses.

Other Uses

There are many more uses of regular expressions. This page was not designed to go into all of the uses; it is only meant to give you a simple overview of how regular expressions are used in Mailman. For more information on specific settings that may use regular expressions, look through the other Mailman help pages on this website, especially the Frequently Asked Questions. While not necessarily mentioning the term “regular expression,” the other pages still contain information on how to accomplish specific tasks by using regular expressions.

For more general information on regular expressions within Python, see Python’s Regular Expression Operations and the Regular Expression HOWTO.

Settings That Use Regular Expressions

The following settings in Mailman will accept regular expressions: