[wp-hackers] .htaccess cleanup
ringmaster at midnightcircus.com
Sun May 22 19:06:34 GMT 2005
Jonathan Leighton wrote:
>Well, I'm just assuming that saying (in code of course) "match any
>character" is faster than saying "match this phrase, or that phrase, or
>that phrase, or that phrase". But yeah, I wouldn't know either.
Not so much. Matching something specific with a regex is *always*
faster than maching anything because when the regex engine hits the end
of the string that it matches, it backs out of the match to find what's
Match that against this:
This would first match the '.*' part against the entire string, and then
backtrack one chracter at a time to find the 'a' that would come next.
7 assertions on 'c's would fail before it found the match. As you can
imagine, '.*?a' is worse on 'bbbabbba'. All of this is subject to
optimization that might improve the performance of the regex, but
speaking generally you shouldn't match against anything when you know in
advance what set of things you want to match against.
Whether this general case can be applied to the regexes mentioned, I
don't know, and whether an inefficient '.*' regex would be faster than
multiple not-'.*' regexes I also can't say. It's a tradeoff that you
would need to measure, and I really don't think my WordPress serving
bottleneck is in the regex configuration. If I was looking to optimize,
I might start elsewhere first.
More information about the wp-hackers