I need a regex that will select only those URL strings NOT ending with specific extensions like .png or .css.
I tested the following:
1) this one using negative lookbehind:
(?<!\.png|\.css)$
https://regex101.com/r/tW4fO5/1
2) this other one using negative lookahead:
^(?!.*[.]png|.*[.]css$).*$
https://regex101.com/r/qZ7vA4/1
Both seems to work fine, but #1 (negative lookbehind) is said to be processed in 436 steps (see the link), while #2 (negative lookahead) is said to be processed in 173 steps.
So my question is: what does that mean? Is it going to have an impact on performances?
And lastly, are the two regex really functionally equivalent?
EDIT: SOLUTION SUMMARY
Just to wrap things up, considering the full list of string-endings to be excluded via the regex (a typical scenario would be a web server setup where static resources are served by apache while dynamic stuff is served by a different engine - in my case: php-fpm).
Two options are possible with PCRE regex:
1) negative lookbehind
$(?<!\.(?:ico|gif|jpg|png|css|rss|xml|htm|pdf|zip|txt|ttf)$|(?:js|gz)$|(?:html|woff)$)
https://regex101.com/r/eU9fI6/1
Notice that I used several OR-ed lookbehinds because the negative lookbehind requires a fixed-width pattern (ie: you cannot mix patterns of different lengths). This makes this options sligthly more complex to write. Moreover this lowers its performance in my opinion.
2) negative lookahead
^(?!.*[.](?:js|ico|gif|jpg|png|css|rss|xml|htm|html|pdf|zip|gz|txt|ttf|woff)$).*$
https://regex101.com/r/dP7uD9/1
The lookahead is slightly faster than the lookbehind. This is a test result from making 1 million iterations:
time lookbehind = 18.469825983047 secs
time lookahead = 14.316685199738 secs
If I had not the issue of the variable lenght patterns, I would pick the lookbehind since it looks more compact. Either one is good anyway. At the end, I went with the lookahead:
<LocationMatch "^(?!.*[.](?:js|ico|gif|jpg|png|css|rss|xml|htm|html|pdf|zip|gz|txt|ttf|woff)$).*$">
SetHandler "proxy:unix:/var/run/php5-fpm.sock|fcgi://www/srv/www/gioplet/web/public/index.php"
</LocationMatch>