The basics of regex - examples & cheat sheet

Published Jan 18 2022 Last updated May 24 2023 2 minute read
a video introducing regex
Contributors

 Have you heard the term “regex” a few times and want to know what it is and how marketers use it to their advantage? In this video I cover:

  • What regex is and how to understand it
  • Give you a few examples 
  • Explain possible applications for marketers


What is regex?

Regex stands for regular expression and is a series of characters that specify a search pattern. Think about how a simple find and replace function in google docs or sheets typically works; you search the word “date,” and it highlights every instance the word “date” occurs in the document. Regex follows a similar logic but is more scalable. Naturally, this makes it slightly more advanced than a typical find and replace.

How marketers use regex to their advantage 

The easiest context for marketers to understand the application of regex is to think about organizing campaign data. Once a marketer has run campaigns on different marketing platforms, they will have created data, data on the performance of those campaigns. That data includes clicks, cost, impressions, click-through rate, and conversions. All information that is needed to take learnings and improve your future campaigns.

But to look at the data in different ways, you may need to organize it so it is neatly aggregated - this is where regex is helpful. If you have consistent naming conventions, which you should. Please read this article, or download this 4 step guide, if you don’t.

As an example your naming conventions could look something like:

Variables: [channel] | [platform] | [geo] | [stage of funnel] | [brand/non-brand] | [usp]

=

Campaign name: Paid social | FB | UK | Think | NB |Time 

 

In this simple example, regex could be used to create custom metrics and dimensions that help you scale the organization of your data. You could create a dimension that searches your naming conventions for the characters after the second pipe, which is “UK.” Then use those characters which indicate the geographical location of the campaign to group different regions together across hundreds of campaigns on various platforms. 

With consistent naming conventions, you could quickly create automated rules to group and map various data together to give you the full picture of your marketing data.

A few examples of regex

colou?r = contains {color, colour}

Hello\nworld = contains Hello followed by a newline followed by world

^dog = begins with "dog"

dog$ = ends with "dog"

^dog$ = is exactly "dog"

As you can see, different types of characters allow for much more complex combinations that can be achieved with regular language.

Going back to our marketing example earlier, we wanted to find the characters indicating geography after the second pipe. The regex query for this would be:

Campaign name: Paid social | FB | UK | Think | NB |Time 

Regex query = ([^|]+)\|([^|]+)\|([^|]+)\|([^|]+)\|([^|]+)\|([^|]+)\s

The following regex allows splitting the string into 6 capture groups split by the character "|". Using this regex with "capture group 3" would return "UK" as the UK is the third group. 

Regex is a powerful way of extracting information in a scalable way. In Funnel, we have created a variety of regex functions, without the need for regex knowledge, sort of like a regex drop-down menu. But we also support regex. Check out this knowledge base article to learn more about using regex in Funnel.

Want to work smarter with your marketing data?
Discover Funnel