Sophie

Sophie

distrib > Fedora > 14 > x86_64 > by-pkgid > 3d4d9cc28af00be9852b4cb3055b122e > files > 114

exim-doc-4.69-4.fc12.noarch.rpm

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><style xmlns="" type="text/css">
div.added    { background-color: #ffff99; }
div.deleted  { text-decoration: line-through;
               background-color: #FF7F7F; }
div.changed  { background-color: #99ff99; }
div.off      {  }

span.added   { background-color: #ffff99; }
span.deleted { text-decoration: line-through;
               background-color: #FF7F7F; }
span.changed { background-color: #99ff99; }
span.off     {  }



pre.literallayout {
  background-color: #E8E8D0;
  padding-left: 0.5cm;
  padding-top:  5px;
  padding-bottom: 5px;
}

div[class=changed] pre.literallayout {
  background-color: #99ff99;
  padding-left: 0.5cm;
  padding-top:  5px;
  padding-bottom: 5px;
}

div.literallayout {
  background-color: #E8E8D0;
  padding-left: 0.5cm;
  padding-top:  5px;
  padding-bottom: 5px;
}

div[class=changed] div.literallayout {
  background-color: #99ff99;
  padding-left: 0.5cm;
  padding-top:  5px;
  padding-bottom: 5px;
}

</style><title>8. Regular expressions</title><meta name="generator" content="DocBook XSL Stylesheets V1.72.0" /><link rel="start" href="index.html" title="Specification of the Exim Mail Transfer Agent" /><link rel="up" href="index.html" title="Specification of the Exim Mail Transfer Agent" /><link rel="prev" href="ch07.html" title="7. The default configuration file" /><link rel="next" href="ch09.html" title="9. File and database lookups" /></head><body><div class="navheader">
<table width="100%" summary="Navigation header"><tr><td width="20%" align="left"><a accesskey="p" href="ch07.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="ch09.html">Next</a></td></tr></table></div>
<div class="chapter" lang="en" xml:lang="en">
<div class="titlepage">
<div>
<div>
<h2 class="title"><a href="index.html#toc0087" id="CHAPregexp">8. Regular expressions</a></h2></div>
</div>
</div>
<p>
<a id="id494569" class="indexterm"></a>
<a id="id494583" class="indexterm"></a>
Exim supports the use of regular expressions in many of its options. It
uses the PCRE regular expression library; this provides regular expression
matching that is compatible with Perl 5. The syntax and semantics of
regular expressions is discussed in many Perl reference books, and also in
Jeffrey Friedl’s <span class="emphasis"><em>Mastering Regular Expressions</em></span>, which is published by
O’Reilly (see <span class="bold"><strong><a href="http://www.oreilly.com/catalog/regex2/" target="_top">http://www.oreilly.com/catalog/regex2/</a></strong></span>).
</p>
<p>
The documentation for the syntax and semantics of the regular expressions that
are supported by PCRE is included in plain text in the file
<em class="filename">doc/pcrepattern.txt</em> in the Exim distribution, and also in the HTML
tarbundle of Exim documentation. It describes in detail the features of the
regular expressions that PCRE supports, so no further description is included
here. The PCRE functions are called from Exim using the default option settings
(that is, with no PCRE options set), except that the PCRE_CASELESS option is
set when the matching is required to be case-insensitive.
</p>
<p>
In most cases, when a regular expression is required in an Exim configuration,
it has to start with a circumflex, in order to distinguish it from plain text
or an “<span class="quote">ends with</span>” wildcard. In this example of a configuration setting, the
second item in the colon-separated list is a regular expression.
</p>
<pre class="literallayout">domains = a.b.c : ^\\d{3} : *.y.z : ...
</pre><p>
The doubling of the backslash is required because of string expansion that
precedes interpretation – see section <a href="ch11.html#SECTlittext" title="11.1 Literal text in expanded strings">11.1</a> for more discussion
of this issue, and a way of avoiding the need for doubling backslashes. The
regular expression that is eventually used in this example contains just one
backslash. The circumflex is included in the regular expression, and has the
normal effect of “<span class="quote">anchoring</span>” it to the start of the string that is being
matched.
</p>
<p>
There are, however, two cases where a circumflex is not required for the
recognition of a regular expression: these are the <span><strong class="option">match</strong></span> condition in a
string expansion, and the <span><strong class="option">matches</strong></span> condition in an Exim filter file. In
these cases, the relevant string is always treated as a regular expression; if
it does not start with a circumflex, the expression is not anchored, and can
match anywhere in the subject string.
</p>
<p>
In all cases, if you want a regular expression to match at the end of a string,
you must code the $ metacharacter to indicate this. For example:
</p>
<pre class="literallayout">domains = ^\\d{3}\\.example
</pre><p>
matches the domain <span class="emphasis"><em>123.example</em></span>, but it also matches <span class="emphasis"><em>123.example.com</em></span>.
You need to use:
</p>
<pre class="literallayout">domains = ^\\d{3}\\.example\$
</pre><p>
if you want <span class="emphasis"><em>example</em></span> to be the top-level domain. The backslash before the
$ is needed because string expansion also interprets dollar characters.
</p>
<div class="section" lang="en" xml:lang="en">
<div class="titlepage">
<div>
<div>
<h3 xmlns="" class="title"><a xmlns="http://www.w3.org/1999/xhtml" href="index.html#toc0088" id="SECID59">8.1 Testing regular expressions</a></h3></div>
</div>
</div>
<p>
<a id="id494740" class="indexterm"></a>
<a id="id494754" class="indexterm"></a>
<a id="id494769" class="indexterm"></a>
A program called <span class="emphasis"><em>pcretest</em></span> 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. After building Exim, the binary can be found in the build
directory (it is not installed anywhere automatically). There is documentation
of various options in <em class="filename">doc/pcretest.txt</em>, but for simple testing, none are
needed. This is the output of a sample run of <span class="emphasis"><em>pcretest</em></span>:
</p>
<div class="literallayout">
<code class="literal">  re&gt; </code><span class="bold"><strong><code class="literal">/^([@]+)@.+\.(ac|edu)\.(?!kr)[a-z]{2}$/</code></strong></span><br />
<code class="literal">data&gt; </code><span class="bold"><strong><code class="literal">x@y.ac.uk</code></strong></span><br />
<code class="literal"> 0: x@y.ac.uk</code><br />
<code class="literal"> 1: x</code><br />
<code class="literal"> 2: ac</code><br />
<code class="literal">data&gt; </code><span class="bold"><strong><code class="literal">x@y.ac.kr</code></strong></span><br />
<code class="literal">No match</code><br />
<code class="literal">data&gt; </code><span class="bold"><strong><code class="literal">x@y.edu.com</code></strong></span><br />
<code class="literal">No match</code><br />
<code class="literal">data&gt; </code><span class="bold"><strong><code class="literal">x@y.edu.co</code></strong></span><br />
<code class="literal"> 0: x@y.edu.co</code><br />
<code class="literal"> 1: x</code><br />
<code class="literal"> 2: edu</code><br />
</div>
<p>
Input typed by the user is shown in bold face. After the “<span class="quote">re&gt;</span>” prompt, a
regular expression enclosed in delimiters is expected. If this compiles without
error, “<span class="quote">data&gt;</span>” 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 <em class="varname">$0</em>, <em class="varname">$1</em>, <em class="varname">$2</em>, etc.) are shown. The above example tests for
an email address whose domain ends with either “<span class="quote">ac</span>” or “<span class="quote">edu</span>” followed by a
two-character top-level domain that is not “<span class="quote">kr</span>”. The local part is captured
in <em class="varname">$1</em> and the “<span class="quote">ac</span>” or “<span class="quote">edu</span>” in <em class="varname">$2</em>.
</p>
</div>
</div>
<div class="navfooter">
<table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch07.html">Prev</a> </td><td width="20%" align="center"> </td><td width="40%" align="right"> <a accesskey="n" href="ch09.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top"> </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> </td></tr></table></div>
</body></html>