Re: [exim] Host Pattern Matching

Page principale
Supprimer ce message
Répondre à ce message
Auteur: Philip Hazel
Date:  
À: Marc Perkel
CC: exim-users
Sujet: Re: [exim] Host Pattern Matching
On Fri, 22 Jun 2007, Marc Perkel wrote:

> I see what you're saying. But in this case the matching string I'm
> looking for is usually on the end of the string. So in my case searching
> backwards would be faster?


No. If you want to know in detail how this kind of regex works, look at
Jeffrey Friedl's book "Mastering Regular Expressions". But I guess I can
spell this one out. Consider

abcd.abcd.yahoo.com

With .* it counts its way through to the end of the string. Then it goes
backwards character by character, looking for . and the checking for
.yahoo. In this case, it has to go back 10 characters.

With .*? it looks for .yahoo. at the start, then at the second
character, etc. This avoids the counting through to the end and the
backtracking. (And in that example, it turns out also to be 10
attempts.)

Yes, of course, in this case it's not actually a big deal either way.
And in the cases where it does not match, it still has to check at every
position. That's how regexs work.

-- 
Philip Hazel            University of Cambridge Computing Service
Get the Exim 4 book:    http://www.uit.co.uk/exim-book