Ok, so I'm doing a mod_rewrite, and I'm in a situation to where I need to match any subdomain except for one. It starts out looking like this.
RewriteCond %{HTTP_HOST} ^([^\.]+)\.example\.com$ [NC]
So that matches and captures a single subdomain, no periods. But let's say I don't want to match the submdomain named 'dog'. I tried to do this with a negative lookahead like so.
RewriteCond %{HTTP_HOST} ^((?!dog)[^\.]+)\.example\.com$ [NC]
This works, for the most part. dog.example.com no longer matches, which is good. However, doggies.example.com also no longer matches. That is not good.
I was able to fix this by using a negative lookahead combined with a negative look-behind like so.
RewriteCond %{HTTP_HOST} ^((?!dog)[^\.]+(?<!dog))\.example\.com$ [NC]
This works. It works perfectly, as far as I can tell. The thing is, I can't believe that is the best way to achieve this match. A lookahead and a look-behind? Really? What is the "correct" way to achieve an equivalent expression?