简体   繁体   中英

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.*

You can use this regex:

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

RegEx Demo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM