Regular Expression Primer

The Regular Expressions Primer is a tutorial for those completely new to regular expressions. To familiarize you with regular expressions, this primer starts with the simple building blocks of the syntax and, through examples, builds to construct complex expressions.

PureMessage uses regular expressions as follows:

  • The Policy Script: Regular expressions can be used as match operators ("Matches regex" and "Does not match regex") for many types of policy rule tests. For example, a regular expression can be used to test the contents of a message's Envelope to field. Certain policy rule actions also support the use of regular expressions. For example, the "Deliver immediately for" action supports the use of a regular expression as a match type for exceptions.

    For information about using regular expressions while editing the policy script via the PureMessage Manager, see "Policy Rule Tests" and "Policy Rule Actions". If you are manually editing the policy script, see pmx-policy (the documentation for the command-line interface to the PureMessage policy engine).

    When regular expressions are used in policy rule tests or actions, they are not prefixed or suffixed with slashes or braces. However, if you are manually editing the policy script on the command-line, you must "escape" backslashes and quotes within regular expressions by preceding them with a backslash. (The PureMessage Manager will automatically escape these characters.) For example, to search for the string "and\or", enter "and\\or" as the regular expression. See "Searching for Special Characters" for more information.

  • Lists: Lists can be configured to contain regular expressions. When creating a new list, specify the "Regular Expression" match type. Individual entries in the list are then entered as regular expressions. They are not prefixed with slashes or braces. It is not necessary to escape special characters in regular expressions contained in lists. For more information about configuring lists, see "Lists".
  • Anti-Spam Rules: Anti-spam rules support regular expressions as the test portion of a rule. For example, the content of a message can be tested against a specified regular expression. Many of the default anti-spam rules supplied with PureMessage are based on regular expressions; custom anti-spam rules exclusively use regular expressions. For information about configuring anti-spam rules, see "Spam Detection".