Go to the first, previous, next, last section, table of contents.


Regular expressions

Exim uses the PCRE regular expression library; this provides regular expression matching that is compatible with Perl 5. The syntax and semantics of these regular expressions is discussed in many Perl reference books, and also in Jeffrey Friedl's Mastering Regular Expressions (O'Reilly, ISBN 1-56592-257-3).

The PCRE distribution files, which are included in the directory `src/pcre' in the Exim distribution, contain a man page for PCRE which describes exactly what it supports, so no further description is included here. The PCRE functions are called from Exim using the default option settings, except that the PCRE_CASELESS option is set when the matching is required to be independent of the case of letters.

Testing regular expressions

A program called `pcretest' forms part of the PCRE distribution and is built with PCRE during the process of building Exim. It is primarily intended for testing PCRE itself, but it can also be used for experimenting with regular expressions. The binary can be found in the `pcre' sub-directory of the Exim build directory. There is documentation of various options in `src/pcre/README', but for simple testing, none are needed. This is the output of a sample run of `pcretest':


  re> /^([^@]+)@.+\.(ac|edu)\.(?!kr)[a-z]{2}$/
  data> x@y.ac.uk
 0: x@y.ac.uk
 1: x
 2: ac
  data> x@y.ac.kr
No match
  data> x@y.edu.com
No match
  data> x@y.edu.co
 0: x@y.edu.co
 1: x
 2: edu

After the `re>' prompt, a regular expression enclosed in delimiters is expected. If this compiles without error, `data>' prompts are given for strings against which the expression is matched. An empty data line causes a new regular expression to be read. If the match is successful, the captured substring values (that is, what would be in the variables `$0', `$1', `$2', etc.) are shown. The above example tests for an email address whose domain ends with either `ac' or `edu' followed by a two-character top-level domain that is not `kr'. The local part is captured in `$1' and the `ac' or `edu' in `$2'.


Go to the first, previous, next, last section, table of contents.