What is RegEx?
Regular Expression, or RegEx as it is commonly called, is a sequence of characters that specifies a search pattern in the text.
RegEx has been around since the 1950s. What number is to maths is what RegEx is to text as it describes a sequence of characters that describes text.
Where Can I Use RegEx? 5 Places You Can Use RegEx
There are many ways and places you can use RegEx as a marketer. However, the most commonly used places/scenario are:
- Google sheets
- Google search console
- Google Analytics
- Looker Data Studio
- Screaming Frog
Where you can use RegEx with Google Sheets
If you are comfortable with Google sheets, there are three Google sheet RegEx formulas you can use
- REGEXEXTRACT will extract text that matches the pattern.
- REGEXMATCH will confirm whether it finds the pattern in the text.
- REGEXREPLACE will replace text that matches the pattern.
Where you can use RegEx with Google Search Console
Here is one example of where a regular expression can be inputted to show a specific result in Google Search Console. In this example, we can choose to show only queries that do match our regular expressions or that do not match the regular expression.
1: Go to Google search console
2: Navigate to the Performance Report
3: Click the +
4: Select Queries – Custom (Regex) – Matches regex
Where you can use RegEx with Google Analytics
Regular expressions can be helpful in Google Analytics as they allow you to customize or segment your data. Using regex code, you can include or exclude data within the report.
For example, using a regular expression, we can filter our acquisition report to include only data where the source/medium matches LinkedIn or Facebook
1: Navigate to Acquisition Report
2: Click All Traffic
3: Click Source/Medium
4: Click Advanced
Another use case within Google Analytics is when using filters. In the second example, you can use regular expressions to filter campaign sources matching your regex code.
In this example, we want to include only traffic sources from Facebook.
1: Go to Google Analytics
2: Admin
3: Filter
Where you can use RegEx with Looker Data Studio
In Looker Data Studio, regular expressions can clean up data, find patterns and automate tasks.
In this example, we created a case statement in the calculated field to group landing pages by topics to give us a clear picture of our best-performing content.
Where you can use RegEx with Screaming Frog
Screaming Frog is a fantastic tool for SEO. We can use Regex to find the information you need in minutes rather than spend hours digging through large amounts of data. In this example, you can for URLs matching your search term in them using the regex .*search_term.*
Why Should You Care About RegEx?
While math is the language of numbers, RegEx is the language of the text. With RegEx, you can speed up/automate workflows such as
- Content Audits
- Content grouping
- Content classification (Funnel Depth Audit)
- Keyword grouping
- Keyword extractions
- Be a more efficient analyst
- Scripts that work for you = save them, reuse
- Less analyzing = more time to write/strategize to drive results.
Basic RegEx Every Content Marketer Needs to Know
There are different types of wildcard RegEx you need to know as a beginner. They include
- ^
- $
- *
- I
Let’s check out what each of them means and how to use it.
RegEx Type | Example | What It Means |
^ | ^(who|what|where|when|why|how) | “Starts with a question” |
$ | .* supplies$ | “Starts with anything, ends with supplies” |
. | .* supplies | Matches any ONE character…The character can be anything |
* | *supplies | Matches the character before 0 or more times |
.* | .* supplies | The character before can be there as many times as itlikes (including not at all) AND can be anything… |
| | (Brand Name|Product 1|Product 2| Product 3) | “Match any brand or product name” |
Different examples of wildcard RegEx
Example for “^”
^(who|what|where|when|why|how)
What it means:
“Starts with a question”
Example for $
.* supplies$
What it means:
“Starts with anything, ends with supplies”
Example for “.*”
.*
What it means:
The character before can be there as many times as it likes (including not at all) AND can be anything…
Example for “*”
Matches the character before 0 or more times
Example for “.*”
.*
What it means:
The character before can be there as many times as it likes (including not at all) AND can be anything…
|
What it means: “This OR That”
Example for “|”
(Brand Name|Product 1|Product 2| Product 3)
What it means: “Match any brand or product name”
How to be efficient with RegEx for faster workflows
Once you create your RegEx, you can reuse it anywhere. Here is an example of how I will use RegEx to extract the domain name from a list of URLs.
Here is an example: =RegExEXTRACT(“https://yourdomain.com”,”^(?:https?:\/\/)?(?:www/\.)?([^\/]+)”)
Useful tools & resources to create, test, and verify RegEx:
- RegEx.tips [My soon-to-be Ultimate Guide – like, an ultimate guide 😉 ]☝🏻 But you can sign up to get notified when this goes live.
- RegEx101 (Create and Test RegEx)
- RexEx101 (Library of Patterns)
- RegEx Hub (Library of Patterns)
- Regular Expression Language – Quick Reference
- https://RegExr.com/ (Create & Verify Patterns)
- Automatic RegEx Generator (Very Cool!)