Re: [exim] Is there a regex escape function?

Page principale
Supprimer ce message
Répondre à ce message
Auteur: Lena
Date:  
À: exim-users
Sujet: Re: [exim] Is there a regex escape function?
Mike Cardwell wrote:

> On 02/10/12 11:24, John Horne wrote:
>
> > I am trying to do a 'match' of one variable against another:
> >
> > ${if match {$h_X-UoP-Loop:} {^$sender_address } }


> > the sender address may well contain '.', which as a regex
> > will match any character. So my question is whether there is any
> > function to escape characters such as '.' so that they can then be
> > used correctly in a regex?
>
> In perl style regular expressions, \Q disables pattern meta-characters
> until \E is reached.


But Exim uses PCRE. From `man pcrepattern`:

       If  you  want  to remove the special meaning from a sequence of charac-
       ters, you can do so by putting them between \Q and \E. This is  differ-
       ent  from  Perl  in  that  $  and  @ are handled as literals in \Q...\E
       sequences in PCRE, whereas in Perl, $ and @ cause  variable  interpola-
       tion. Note the following examples:


         Pattern            PCRE matches   Perl matches


         \Qabc$xyz\E        abc$xyz        abc followed by the
                                             contents of $xyz