Re: [exim] Exim regex limit length

Top Page

Reply to this message
Author: Mike Brudenell
Subject: Re: [exim] Exim regex limit length
Hi, Emanuel -

I'm not quite sure what you mean by "create it in more directions" but from
the example you give afterwards I'm guessing you're wanting to match
Subject text when:

- there are between 0 and 20 characters, and then
- the string "Unlock Your Account" with exactly those upper and lower
case letters, and then
- between 0 and 20 characters to the end.

If that's the case then you're almost right with your second example, but
not quite. Try this instead:

${if match{$header_subject:}{\N^.{0,20}Unlock Your Account.{0,20}$\N}}

I'll take the time to talk you through this, but really you need to read
and learn about PCRE regular expressions — that is, the sequences of
special characters you can put into a pattern to make it match against what
you want. Please take the time to do so.

But for this time…

   - The "match" expansion condition takes two arguments: the first is the
   text string you want checking, and the second the regular expression to
   compare it again. Each of these in enclosed within braces ("curly
      - The first argument is therefore the value of the Subject header
      — $header_subject:
      - The second argument is the regular expression you're wanting to
      match against — \N^.{0,20}Unlock Your Account.{0,20}$\N

      - Breaking the second argument down, you'll see it is enclosed within
   "\N" at its start and end. These tell Exim that the content within these
   markers is a regular expression and not to expand it further. So that
   leaves us with the regular expression itself, which is
   ^.{0,20}Unlock Your Account.{0,20}$

Looking at each element of this in turn:

1. The "^" at the start means "the start of the text string". (That's
what Jeremy was referring to when he was talking about the search in your
original question not being anchored to the start of the string. Without
this the next bit wouldn't achieve anything useful.)

2. "." means "any one character" — this can be anything: letter, digit,
punctuation character.

3. Then comes "{0,20}" which means "between 0 and 20 instances of the
thing just before". In this case the thing just before the "{0,20}" is the
"." — so altogether we have ".{0,20}" which means "between 0 and 20

4. Next we've got the exact string "Unlock Your Account" which must
appear exactly like that, including the right mix of upper and lower case
characters. So, for example, "Unlock your account" would NOT match the
pattern whilst "Unlock Your Account" would.

5. Next we have the same ".{0,20} as before — meaning "between 0 and 20

6. Finally there is a "$", which means "the end of the text string" (in
effect it's the opposite of "^").

So putting all that together, "^.{0,20}Unlock Your Account.{0,20}$" means
"The start of the string, followed by between 0 and 20 of any characters,
followed by the exact string 'Unlock Your Account', followed by between 0
and 20 of any characters, followed by the end of the string."

If you wanted to also match "Unlock your Account", "Unlock your account",
"unlock your account" and so on then you can add in "(?i)" which makes the
rest of the regular expression match content without worrying about whether
letters are upper or lower case:

${if match{$header_subject:}{\N^.{0,20}(?i)Unlock Your Account.{0,20}$\N}}

*Where next…*
You can probably track down a tutorial on the web for regular expressions,
but be careful as there are lots of 'flavours' of regular expression, with
slightly different syntaxes: regular expressions, extended regular
expressions, and so on. Exim uses PCRE (Perl Compatible Regular
Expressions), which is generally a superset of most other forms. (I'm sure
I'll be lambasted for saying that, but it's largely true.)

So even if you just start by learning about basic regular expressions
you'll be on the right path. Maybe somewhere will get you going. Someone
else might know of a better tutorial though.

It's important that you have a read and learn about regular expressions if
you're going to be using them. You can't rely on us creating or correcting
them for you all the time.

Mike B-)

On 23 April 2018 at 13:41, Emanuel Gonzalez via Exim-users <
exim-users@???> wrote:

> Hello.!!
> This rule is work fine:
> ${if match{$header_subject:}{\N^.{0,20}Unlock Your Account$\N}}
> Is it possible to create it in more directions?
> ${if match{$header_subject:}{\N^.{0,20}Unlock Your Account{0,20}.\N^}}
> I await the final instructions to close the case, thanks to all
> --
> ## List details at
> ## Exim details at
> ## Please use the Wiki with this list -

Systems Administrator & Change Manager
IT Services, University of York, Heslington, York YO10 5DD, UK
Tel: +44-(0)1904-323811