Perl Compatible Regular Expressions

Rick Cooper rcooper at dwford.com
Mon Dec 19 14:52:33 GMT 2011


Paul Welsh wrote:
> Hi all
> 
> Apologies this is off topic.
> 
> I have a quick question about Perl Compatible Regular Expressions.
> I'm using Exim 4.x and a greylist application in conjunction with
> MailScanner obviously.
> 
> The greylist application has a whitelist to cope with senders that,
> when greylisted, try sending again using a different server rather
> than with the same one.
> 
> The whitelist is MTA dependent.  Exim supports Perl Compatible Regular
> Expressions but I'm struggling to match on part of the hostname.  For
> example, this works fine:
> *.domain.com
> - matches mail.domain.com, xxx.mail.com, etc
> 
> What I want to match, however, is something like:
> mail*.domain.com
> which would match say mail01.domain.com, mail02.domain.com, etc
> 
> I think I need to use the ^ symbol but after much googling can't
> figure it out.  I've tried umpteen permutations to no avail.  Any
> ideas?
> 
> Alternatively, if what I'm seeking to do is very complex, does anyone
> know whether Exim can cope with IP subnets that don't include a whole
> octet?  I've discovered belatedly that the whitelist can cope with,
> for example:
> 84.95.1.0/24
> but not:
> 84.95.1.0/26
> 
> Any assistance gratefully received.

First of all mail*.domain.com would match on mai+l none or more
times+.domain.com and that is assuming that you are actually meaning
mail*\.domain\.com (since perl would require the back slash to say match a
dot not any char)

If you are trying to match mail+anything goes+.domain.com you would want
something like:

^mail.*\.domain\.com which says match mail.(anything)*(none or more
times)+dot+domain+dot+com and start matching on the first char. If matching
numbers is important and nothing will be between the word mail and the
number then

^mail[0-9]+\.domain\.com (match mail+numbers 1 or more times)
But if there is likely to be something between mail and the number then
^mail(.)?[0-9]+\.domain\.com would match mail-01.domain.com or
mail01.domain.com. If you need to match just mail.domain.com as well then

^mail(.)?[0-9]*\.domain\.com

And then you have to be clear on how reg exes work in exim and the value of,
say \N, in exim's reg ex implementation which is a bit different because of
expansions. 

On the second point of 84.95.1.0/24 or 26 clearly the /26 will not match on
Ips above 63 and I would have to check and see of exim would consider 63 at
all since in that subnet 63 would be the broadcast address and should not be
assigned a host would would not technically work since the first and last
*usable* Ips would be 1 and 62 (with 0 being network and 63 being broadcast
if 0 is the network). It would be better to ask in the exim list if exim
would consider .63 against a 26 bit mask since it should not occur if the
subnet in question really is 0/26 then 63 would actually match only the 0/24
subnet as a host IP. In other words if my ip is 10.10.10.63 it would not
match 10.10.10.0/26 but would match 10.10.10.0/24

Rick


More information about the MailScanner mailing list