Acts7Seven
Acts7Seven

Reputation: 417

regex to allow "www" (optional) but exclude subdomains on Google Analytics

I am attempting to exclude all subdomains but still allow www. (optional) And then anything after the domain name is optionally allowed

Here is what I'm looking for:

www.domain.com       // true
domain.com           // true
sub.domain.com       // false
domain.com/hello     // true
www.domain.com/hello // true

Here is what I have:

^(?i)(?:www\.)?domain.com.*

This is still allowing other subdomains.

I have tried

^(?i)(?:www\.)(?![-\w.])?domain.com.*

Upvotes: 1

Views: 1202

Answers (1)

anubhava
anubhava

Reputation: 785098

You can use this regex:

^(www\.)?domain\.com(\/.*)?$

RegEx Demo

Upvotes: 1

Related Questions