Re: [exim] Regex Parsing help

トップ ページ
このメッセージを削除
このメッセージに返信
著者: Phil Pennock
日付:  
To: Marc Perkel
CC: exim-users
題目: Re: [exim] Regex Parsing help
On 2009-03-10 at 10:33 -0700, Marc Perkel wrote:
> I'm really not good at regex. And this should be simple stuff. Here's
> what I'm trying to do.


Exim uses PCRE, also written by Philip Hazel. PCRE as a separate
package (as you'll require for building Exim in future, since the
internal copy has been removed) ships with a tool called "pcretest".

The biggest differences between REs in Exim and in pcretest are that
pcretest requires a delimiter around the RE (typically /.../) and Exim
supports \N...\N to protect against Exim's own interpolation of
$variables; you'll need \N wrapping or to use \$ if any appear. This
can be thought of "get through the Exim layer to the PCRE layer".

> I have a list of domain names in a string such as:
>
> set acl_c_domain_list = domain1.com domain2.com domain3.com
>
> The delimiter is a space but I can make it anything. What I want to do
> is set two variables. The first variable will have the first domain in
> the list, no spaces, (domain1.com) and the second variable will have
> the rest of the list items, no leading space. (domain2.com domain3.com )
>
> How do I do that?


% pcretest
PCRE version 7.8 2008-09-05

re> /^(\S+)\s+(.+)$/
data> domain1.com domain2.com domain3.com

0: domain1.com domain2.com domain3.com
1: domain1.com
2: domain2.com domain3.com
data>


So:
\N^(\S+)\s+(.+)$\N

pcretest has a man-page.

PCRE includes a full suite of man-pages, including pcrepattern(3) which
gives you the exact grammar supported by PCRE, as opposed to generic
system regexp libraries, which will (almost certainly) be POSIX (basic
or extended) and much more limited.

-Phil