What are Regular Expressions (RegEx) and RegEx Strings?
A Regular Expression, commonly referred to as RegEx, is a formula that uses unique operators, such as “|” or “$”, to isolate a certain subset of data from a larger dataset.
So that begs to question, what is a RegEx string? Let’s look at an example.
Say you’re working on the Seer Interactive website and you provided metadata and on-page recommendations for 5 pages that just got implemented on the site:
Your next step is to log in to Google Analytics and look at the performance of your new changes, but as you may have come across before, your Google Analytics view has A LOT of URLs. Seer, for example, has upwards of ~1,300 unique URLs.
So how can we isolate the 5 URLs that we optimized to quickly check the performance of our recommendations?
Enter the RegEx string. In its final version, it would look like this:
Below we’ll talk about the underlying operators in this RegEx string and how they impact what we will eventually see within Google Analytics or your desired platform.
Common RegEx Operators You’ll Need for SEO Reporting
RegEx can take many forms depending on the platform you’re using (think Google Analytics, Google Data Studio, Screaming Frog, etc). For the purposes of SEO reporting, here are three main operators you’re going to need to have on hand.
- ^ or Caret - tells Google Analytics that you’re starting the RegEx string
- In our example, you can see how our RegEx string starts with the ^ and each subsequent URL that we’ve optimized starts with a ^ (bolded below)
- $ or Dollar Sign - tells Google Analytics that for a given URL, we don’t want to see any other URL that may live on that subfolder and nothing should come after the $
- In our example, you can see how our RegEx string has a $ after every URL (bolded below)
- Why does this matter? Say, for instance, we didn’t include a $ after the URL www.seerinteractive.com/blog/ within our string (underlined below). This means that we’re telling Google Analytics to pull every single URL on the seer interactive website that is under the /blog/ subfolder instead of just isolating the one URL that we want to isolate from the rest of the group.
- | or Pike - tells Google Analytics or Google Data Studio that we’d like to isolate and only look at URL A OR URL B OR URL C OR etc…
- In theory, you can read our RegEx string to yourself like so:
How to Implement RegEx for SEO Initiatives
Now that we’ve created our RegEx string, we can navigate into Google Analytics and go through the following steps:
- Navigate to a Landing Page View of your choice. For example:
- Acquisition > Channels > Organic Search
- Behavior > Site Content > Landing Pages
- Select Advanced
- Within the field that opens up, select the drop-down option and select “Matching RegExp”
- Paste in your RegEx String (a completed example is pictured below)
- Click “Apply”
The final view within GA will now filter for only the URLs within your string and look something like this:
Now remember; the point of using RegEx is to track our SEO performance for pages that we’ve recently optimized. Don’t forget to adjust your date range to reflect the date on which your changes went live!
Example: If we implemented changes to those 5 Seer Landing pages on February 14th, 2020 then we should be looking at a time range that reflects an equal number of days before and after February 14th, 2020 by using the previous period function within the date range filter in GA.
The Importance of RegEx
In summary, RegEx and RegEx strings are a powerful and efficient way to track performance of SEO recommendations from within Google Analytics. By isolating a subset of URLs from a larger set, we can properly report on the value we’re driving for our clients or business.
For more information on how to implement RegEx, check out our post on using Regular Expressions to Create Filters in GA.