Reputation: 1277
I have a regex which is bothering me really!
What I want, is all subdomains except www.domain.com
goes to www.domain.com
This actually works, but w.domain.com
doesn't match. Actually, if the subdomain contains the character "w" it fails.
This is how it looks:
[^www]+\.domain.com
What am I doing wrong?
Upvotes: 1
Views: 873
Reputation: 417
I know this is old - but to avoid a duplicate post -- how would you do the opposite?
allow www (optionally) but exclude all subdomains?
ALLOWED www.domain.com domain.com
NOT ALLOWED spider.domain.com me.domain.com
Upvotes: 0
Reputation: 5768
.*(?<!www).domain.com
Will match all subdomains EXCEPT www.domain.com
Check here http://regexr.com?30od1
Upvotes: 1
Reputation: 2113
brackets, []
, denote a character class. Using ^
in a character class means you're negating it. [^www]
actually means any character except w
is going to be matched.
Upvotes: 2