Woman looking at a desktop computer

How to Create a Regex in Google Analytics

Allison Soper  |  May 03, 2017

Regex, aka Regular Expression, is a function you can use in Google Analytics to create advanced filters, goals, segments, audiences, content groups and channel groupings.

To better understand how Regex works, we’ve broken down some of the standard characters used in regular expressions, efficient ways to use the solution and how to use Regex to manage large portions of data.

Standard Characters

.  Matches any single character (letter, number or symbol)

?  Matches the preceding character 0 or 1 times

+  Matches the preceding character 1 or more times

|  Creates an OR match

$  Signified the end of a line

\  Escapes the character following it

*  Matches zero or more of the previous character

Ways To Use Regex

Regex can be used in numerous scenarios in Google Analytics. One example would be creating a Referral Spam Filter. A few sources in your Referral Report may look suspicious, so you’ll want to remove them to make sure your data is as clean as possible. To remove it, you’ll need to use the pipe symbol (|) which means “or.” For example, if you see the following spam in your Referral Report, you’ll want to create a Filter Pattern to remove the spam using the pipe symbol.

  • Referralpage.com
  • Referral.com
  • Spam
  • Junk

Take Note: you can also use the pipe symbol when searching for something within Google Analytics.

Another standard situation is if you need to create a filter that excludes several internal IP addresses. You can create a Regex that captures all IP addresses without actually having to type out each IP address.

Dealing With Lots of Data

Finally, sometimes you may come across a ton of data from an external file (such as SKU data or a data dump from BigQuery). To parse the data into a Regex, you can use in Google Analytics for a Custom Report, use a delimited rule. To do this, follow these steps:

  1. Copy the data and paste it into Notepad to strip the table
  2. Copy the data from Notepad and paste it into a Word document
  3. In the Word document, Replace ^p with |
  4. Copy and Paste the separated data into a Custom Report

Take a look at Regexr.com to learn more and practice Regex building.


Allison Soper

Allison Soper

Digital Analyst

Allison currently works on a variety of different accounts where she installs, optimizes and reports with Google Analytics and other similar tools. She also provides recommendations and insights to clients, performs quality assurance tests and produces weekly and monthly dashboards. Prior to Vertical Nerve, Allison worked at Weber Shandwick, a global Public Relations firm, where she was an Account Supervisor of the Analytics & Insights practice.

Become a Nerd

Sign up to receive tips and updates about all things digital marketing.

Leave a Comment