Practical Applications of Regex in SEO

Table of Contents

Regular expressions in SEO are an ultimate time saver. It can help greatly with analysis and loads of different SEO Operations.

In this blog post, we will go through some practical applications of Regex in SEO

What is a REGEX?

Regex means regular expressions which are used to find & match, extract or replace a predefined pattern. In SEO we have to deal with a lot of data when it comes to analysis & keyword research. This is where regex will come to save your day.

Examples of Regex and What they do?

Regex

What it does

^

Starts with

$

Ends with

\s

Matches whitespace

[a-z]

Matches a to z

|

This or that

[[:upper:]]

Matches Uppercase

Want some more examples, grab this Google Sheet that I am maintaining!

regex google sheets

I. Applications of Regex in a Google Sheet

Why would you need to use Regex in a Google Sheet?

Regex comes in really handy in Google Sheets when doing bulk data analysis like traffic segmentation into buckets, URL segregation etc. And it also comes in handy when performing giant keyword research.

Here are some common instances under which you would want to use regex on Google Sheets

1. Website Migration Redirection Mapping: 

You have stage URLs or existing site URLs in the column & in the next column, you want to mention where they should be redirected. Using REGEXREPLACE you replace the subdomain or subdirectory & speed up the process with just one formula.

Example: www.example.us/product/abc should be redirected to www.example.com/en-us/product/abc in this case, your REGEXREPLACE would be

				
					=REGEXREPLACE(A1,".us",".com/en-us")
				
			

2. Keyword Research Clustering & Segmentation

Let’s say you have performed bulk keyword research & now you want to create clusters based on some clusters that you have in mind. Keeping those clusters in mind you did the keyword research, to begin with.

Here are some examples or instances

– You want all the question keywords in one bucket:

For this the Regex we can use is

				
					=IF(REGEXMATCH(A1,"^(what|why|how|where|whom)"),"Question Keyword", "Not a question keyword")
				
			

– You want all the similar keyphrase/keyword keywords in 1 bucket

For example, you have done keyword research for a travel domain for different cities & countries. You want to create clusters by country. 

Here is a Regex you can use,

				
					=REGEXEXTRACT(A1,"India|United States|\sUS|Australia|New Zealand|Germany")
				
			

this Regex extraction will extract those country names for you. Then using the QUERY formula you can do different country keyword research in different tabs.

Now in every country keyword research, you want to create more clusters, like places to visit, things to do, surfing, hiking, and trekking. So again, you can take the same approach of REGEXEXTRACT to extract the values & create subclusters. You can use the same approach when you are doing traffic analysis resulting from different clusters.

I am not implying that REGEX is going to replace the need for a keyword clustering tool. But it is certainly going to help you create clusters faster than the traditional approach.

II. Applications of Regex in a Google Analytics

1. Getting Google Analytics Traffic data for specific subfolder/Slugs

google analytics regex use case 1

 

Here in this example, I have used a Regex to get Google Analytics Traffic data specifically from just two URLs. You can do the same for subfolders.

This is handy when you are dealing with a large website. A website having let’s a million pages. If using GDS you just export the pages, either your GDS will fail to provide you with the export or will hang or you will never be able to open the export. With Regex, you can export specifically what you want.

2. Finding GA Traffic Data from specific Referral Sites

Let’s say you are a brand that is investing heavily in Performance Marketing wherein your ad is displayed on certain websites. Now you want to figure out how many pageviews where those websites were responsible for. Using Regex you can figure that out.

google analytics regex use case 2

III. Applications of Regex in Google Data Studio (Looker Studio)

I have done an entire blog post on the same as to how you can use Regex to do traffic segmentation on Google Data Studio,

Have a read about that to understand how Regex logic works here

GSC Query Segmentation Visualization on Data Studio with Regex

google data studio intent based query segmentation

IV. Applications of Regex in Screaming Frog

Screaming Frog has put together an amazing guide on how to use Regex for custom extractions from the web pages you are crawling.

One of my favourite use cases is to extract the schema code from every web page to audit their schemas.

screaming frog regex

Resource to learn Screaming Frog Regex

V. Applications of Regex in Google Search Console

For Google Search Console Regex I have published an entire article that will teach you different use cases of Regex in Google Search Console.

google search console regex match pages

Leave a Comment