mewm
mewm

Reputation: 1277

All subdomains to www with exceptions

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

Answers (3)

Acts7Seven
Acts7Seven

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

Jack
Jack

Reputation: 5768

.*(?<!www).domain.com

Will match all subdomains EXCEPT www.domain.com

Check here http://regexr.com?30od1

Upvotes: 1

claesv
claesv

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

Related Questions