0

I want to have a regular Expression for Google Analytic so I can match all the domain including the sub domains

say we have to match a domain name called xyz.com

So i want to match every url that have xyz.com in it. Example

abcd.xyz.com, abc1232.xyz, www.xyz.com, www.xyz.com/abc

Can anyone help me with that.

My purpose to it to have the traafic reports excluded in Google Analytics that are coming from these sites.

isherwood
  • 58,414
  • 16
  • 114
  • 157
Anu Sha
  • 21
  • 4

3 Answers3

1

In general, the regular expression to match those domains would be something like .*\.xyz\.com$. The backslashes escape the dots (which are normally wildcard characters and the dollar-sign represents the end of the string.

There are different regex implementations, so you might have to tweak this for your regex engine.

Vince
  • 3,962
  • 3
  • 33
  • 58
  • 1
    The regex engine used by GA is RE2. The `.*` is redundant, since partial matches are accepted. However, the `$` requires a string end, while most addresses do not only contain domain names. – Wiktor Stribiżew Jan 05 '16 at 10:27
0

To exclude subdomains like described above you can use GA filter([Exclude] [Hostname] [Matching RegEx]) along with regular expression (xyz.com)|(.*.xyz.com). This RegEx including both main domain and it's subdomains.

Ruslan Konygin
  • 1,019
  • 6
  • 7
0

You could try this regex

(.*\.)?xyz\.com

This matches all your required formats for the URL.

nyuen
  • 8,829
  • 2
  • 21
  • 28