<!DOCTYPE html PUBLIC "XSLT-compat"> <html lang="en-GB"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <link rel="stylesheet" type="text/css" href="../../../../common.css"> <meta name="author" content="The Exim Project. <http://www.exim.org/>"> <meta name="copyright" content="Copyright ©2010 The Exim Project. All rights reserved"> <meta name="description" content="Exim is a message transfer agent (MTA) developed at the University of Cambridge for use on Unix systems connected to the Internet."> <meta name="keywords" content="exim,smtp,mta,email"> <meta name="robots" content="noodp,noydir,index,follow"> <meta name="viewport" content="width=device-width"> <title>8. Regular expressions</title> <link rel="stylesheet" type="text/css" href="../../../../doc/chapter.css"> <link rel="canonical" href="http://www.exim.org/exim-html-current/doc/html/spec_html/ch08.html"> </head> <body> <h1 id="header"><a href="../../../..">Exim Internet Mailer</a></h1> <div id="outer"> <ul id="nav_flow" class="nav"> <li><a href="../../../../index.html">Home</a></li> <li><a href="../../../../mirrors.html">Download</a></li> <li><a href="../../../../docs.html">Documentation</a></li> <li><a href="../../../../maillist.html">Mailing Lists</a></li> <li><a href="http://wiki.exim.org/">Wiki</a></li> <li><a href="http://www.exim.org/bugzilla/">Bugs</a></li> <li><a href="../../../../credits.html">Credits</a></li> <li class="search"><form action="http://www.google.com/search" method="get"> <span class="search_field_container"><input type="search" name="q" placeholder="Search Docs" class="search_field"></span><input type="hidden" name="hl" value="en"><input type="hidden" name="ie" value="UTF-8"><input type="hidden" name="as_qdr" value="all"><input type="hidden" name="q" value="site:www.exim.org"><input type="hidden" name="q" value="inurl:exim-html-current"> </form></li> </ul> <div id="inner"><div id="content"> <a class="previous_page" href="ch07.html"><-previous</a><a class="next_page" href="ch09.html">next-></a><div id="chapter" class="chapter"> <h2 id="CHAPregexp" class="">Chapter 8 - Regular expressions</h2> <p> 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="docbook_emphasis">Mastering Regular Expressions</span>, which is published by O’Reilly (see <span class="docbook_emphasis"><a href="http://www.oreilly.com/catalog/regex2/">http://www.oreilly.com/catalog/regex2/</a></span>). </p> <p> The documentation for the syntax and semantics of the regular expressions that are supported by PCRE is included in the PCRE distribution, and 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 “ends with” wildcard. In this example of a configuration setting, the second item in the colon-separated list is a regular expression. </p> <div class="docbook_literallayout"><pre> domains = a.b.c : ^\\d{3} : *.y.z : ... </pre></div> <p> The doubling of the backslash is required because of string expansion that precedes interpretation – see section <a href="ch11.html#SECTlittext" title="11. String expansions">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 “anchoring” 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 class="docbook_option">match</span> condition in a string expansion, and the <span class="docbook_option">matches</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> <div class="docbook_literallayout"><pre> domains = ^\\d{3}\\.example </pre></div> <p> matches the domain <span class="docbook_emphasis">123.example</span>, but it also matches <span class="docbook_emphasis">123.example.com</span>. You need to use: </p> <div class="docbook_literallayout"><pre> domains = ^\\d{3}\\.example\$ </pre></div> <p> if you want <span class="docbook_emphasis">example</span> to be the top-level domain. The backslash before the $ is needed because string expansion also interprets dollar characters. </p> </div> <a class="previous_page" href="ch07.html"><-previous</a><a class="next_page" href="ch09.html">next-></a> </div></div> <iframe id="branding" name="branding" src="../../../../branding/branding.html" height="0" frameborder="no" scrolling="no"></iframe><div id="footer">Website design by <a href="https://secure.grepular.com/">Mike Cardwell</a>, of <a href="http://cardwellit.com/">Cardwell IT Ltd.</a> </div> <div class="left_bar"></div> <div class="right_bar"></div> <div id="toc"> <ul class="hidden"></ul> <img src="../../../../doc/contents.png" width="16" height="155"> </div> </div> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script><script type="text/javascript" src="../../../../common.js"></script><script type="text/javascript" src="../../../../doc/chapter.js"></script> </body> </html>