Looker Studio (formerly known as Data Studio) offers more than just drag-and-drop options for designing effective data visualizations and generating reports. 

There’s a cliché that encourages people to read “between the lines.” Coding languages do just that when setting up calculated fields or writing metadata into your visualizations. 

Google Looker Studio regex offers a wide variety of functions that you can add to calculated fields to make your visualizations more customizable. 

Keep reading to learn how to use this feature using Looker Studio.

Free GA4 Audit - Data Bloo V2

What Is a Regular Expression?

A regular expression is what you call a search pattern defined by a sequence of special characters. The regular expression often gets shortened to “regex” or “regexp.” Regular expressions also can be called rational expressions.

For this article, we will stick to the term Regular Expression and its shortened form “regex.”

Regular expressions describe patterns, or more specifically, a finite group of strings. These groups of strings get applied for certain uses within calculated fields. 

Below you can see which operations get applied frequently to form regular expressions:

  • Grouping
  • Boolean
  • Quantification
  • Wildcard

For boolean expressions, vertical bars separate the different alternatives for a regular expression. Grouping relies on parentheses to separate alternatives as different options (/product/|?product-tag/).

To apply quantification, you add a quantifier symbol to denote how many times that element can repeat. The most commonly used quantifier symbols include the following:

  • ? to specify zero or one occurrence of the element
  • * to specify zero or more occurrences of the element
  • + specifies one or more occurrences of the prior element

Quantifications can also rely on explicit commands that can be keyed in with text functions. The most commonly used text functions include the following:

  • {n} the element matches “n” number of times
  • {min,} the element matches the “min” amount or more times
  • {, max} the element matches up to the “max” amount of times
  • {min, max} the element can match at least min amount of times but no more than the max amount of times

Finally, the wildcard function uses the “.” symbol to match any character. For example, a.b matches strings that contain “a” with strings that contain “b.” If you typed in a.*b, then you can match with strings that contain “a” and also contain “b” at a point further down.

looker studio regex

Patterns in Regular Expressions

Patterns are represented by regular expressions using standard text syntaxes. These sequences identify the set patterns from which calculated fields search for matching texts that fulfill the specified requirements. 

Regex patterns comprise a sequence of smaller units called atoms. Single atoms denote literal meanings, but when you group atoms, metacharacters such as [ ] or { } will be needed to identify the patterns to match. Patterns match targeted groups of texts known as strings. 

Strings that comprise regular expressions contain two different types of characters. Metacharacters have special meanings, whereas regular characters rely on literal meanings. 

Regular expressions contain combinations of metacharacters and regular characters. These characters search for and identify texts that fit a specified pattern. They also count the number of times a specified pattern appears within a body of text.

Metacharacters decide whether a regex identifies a very specific textual pattern or similar patterns. They direct automated text processing that represents targets in precise and flexible ways. 

What Regular Expressions Do

Regex has been used for identifying complete or partial patterns in strings. This often includes text data. Some uses for this type of matching function include the following:

  • Finding substrings within structured strings
  • Splitting a string into tokens
  • Verifying a string’s structure
  • Search, replace, or rearrange parts of strings

All of these function as part of preparing and mining large groups of data. Regex patterns create the commands for which pieces of data to extract, or which patterns to identify from raw data.

Types of Regex and Regex Symbols/Characters

Google Looker Studio regex rely on a simplified type of regex. The following symbols denote specific commands in regex patterns.

Basic regular expression symbols include the following:

  • Dot <.> which matches any specific characters -> bl. matches "blo", “bloo" and “blue"
  • Question mark <?> sets the preceding characters as options to manipulate numbers or catch multiple spellings -> bloo? matches “bloo” and “blo"
  • Plus sign <+> preceding characters can repeat one or more times -> blo+ matches “blo”, "bloo" "blooo"
  • Asterisk <*> means preceding characters can repeat zero or more times -> bl* matches “bl","bloo","blue"
  • Vertical bar <⎹ > denotes “or” for when you want to match more than one variation -> bloo|blue matches “bloo" and "blue"
  • Dollar sign <$> denotes an exact end of a query -> bloo$ matches “bloo", "databloo" and "data bloo"
  • Caret sign <^> sets up the beginning pattern so only matches that have that same beginning appear -> ^data matches “data", "databloo" and "data bloo"

The following expressions use combination symbols to define queries:

  • Parentheses ( ) enclose expressions in exact order or group expressions together
  • Square brackets [ ] create lists by matching characters inside the brackets
  • Curly brackets { } repeat preceding characters a set number of times and can set a minimum and/or a maximum
  • Dash or hyphen – get used inside square brackets to create lists
  • Backslash removes a symbol from a regex function

Regular expressions contain special elements known as literals, escapes, groupings, quantifiers, the OR function, or boundary matches. These types make up specific building blocks that define what patterns the regex wants to make appear. The symbols listed above define which type of patterns the regular expression creates. 

How to Use Regex in Google Looker Studio

When using regex in Google Looker Studio, you can set up options for customizable filters in your control settings. Regex also functions as part of calculated field formulas. Google Looker Studio uses the following commands to perform regex functions:

  • REGEXP_CONTAINS which will return true if the regular expression is contained within the input value -> when REGEXP_CONTAINS(Query,"best|top|review|comparison|vs|compare") Then "Commercial"
  • REGEXP_ EXTRACT brings back the first substring match
  • REGEXP_MATCH this returns true if the regular expression matches the input value -> when REGEXP_MATCH(Query,”.*data bloo.*|.*databloo.*”) Then “Brand Keywords”
  • REGEXP_REPLACE replaces specific occurrences of text that matches regex pattern with special replacement strings

When applying one of these four commands, you input which symbols you want to specify in your regular expression patterns.

Tips for Using Google Looker Studio Regex

Regular expressions can provide valuable uses for setting up your charts and control fields. Here are some tips to get the most out of using regex in Google Looker Studio.

First, you want to keep your regex patterns as simple as possible. This makes them easy for other users to identify and accurately interpret.

You also want to be aware that all commands in regular expressions automatically become case-sensitive. If you don’t want a command to be case sensitive, you type in the following function: (?i), which means case insensitive.

Backslashes come in handy when you need escapes. This will help when you want to make metacharacters give literal commands.

Bonus Tip: In case you want to double-check your regular expression before adding it to a Looker Studio formula, you can try out Autoregex which allows you to translate English to Regex.

Input: Match all numbers between 2 and 100 | Result: [2-9]|[1-9][0-9]|100

Make Regex Commands Look Simple

You don’t need to be a master expert in coding to make use of regular expressions with Google Looker Studio. The interface makes it very simple and easy to figure out for users of all levels. 

Google Looker Studio regex offers advanced options for highly tailored searches from raw data. You have more control and options to specify exactly what patterns or data points you want to find and use in your charts. Visit our templates gallery to upgrade your digital reporting in minutes.

Related Topics

Upgrade your reporting today!

Try our free demos and see the difference. No payment required.
Data Bloo Footer Background