What Does Regex Mean in Google Analytics?

Cody Schneider11 min read

If you've ever poked around in Google Analytics, you’ve probably seen the term "regex" and quickly moved on, assuming it was some complex code only a developer could understand. The good news is that regex isn't nearly as scary as it looks, and learning a few basics can completely transform how you analyze your data. This article will show you what regex means in Google Analytics, why it’s useful, and provide practical examples you can start using today.

GraphedGraphed

Still Building Reports Manually?

Watch how growth teams are getting answers in seconds — not days.

Watch Graphed demo video

What is Regex, Anyway?

Regex, short for "Regular Expression," is a special sequence of characters that defines a search pattern. Instead of searching for one specific piece of text like "contact-us," you can use regex to search for patterns that match your criteria. Think of it as a super-powered find-and-replace for your data.

For example, you could create a single regex pattern to find all of these pages at once:

  • /blog/top-10-marketing-tips
  • /blog/guide-to-seo-basics
  • /blog/how-to-write-great-emails

Instead of creating three separate filters, regex lets you find everything that fits the pattern "/blog/..." with just one simple expression. It’s all about working smarter, not harder.

Why Should You Use Regex in Google Analytics?

Manually filtering your reports one page or one campaign at a time is tedious and time-consuming. Regex unlocks a more flexible and efficient way to analyze your performance and uncover deeper insights.

  • Save Time & Reduce Manual Work: Instead of applying ten different filters to see data from ten different landing pages, you can write one regex expression that groups them all together. This is especially useful for campaign analysis, content grouping, and goal tracking.
  • Get More Granular Insights: Regex lets you create highly specific segments and filters that aren’t possible with the default "contains" or "exactly matches" options. You can isolate traffic from multiple countries, group different versions of a landing page, or consolidate data from multiple subdomains.
  • Create Cleaner Reports: URLs can get messy with campaign parameters, user IDs, or other random strings. Regex helps you clean them up, allowing you to focus on the core information without getting lost in noisy data.

The Most Common Regex Characters You'll Need For Google Analytics

You don't need to be a programmer to use regex. You just need to know a handful of special characters, called "metacharacters," that act as instructions. Here are the essential ones you’ll use most often in Google Analytics.

The Pipe: |

This is the "OR" statement and arguably the first and most useful character to learn. It lets you match one thing OR another.

Example: In your Source/Medium report, you want to see all traffic from your main social media channels. You can use the expression facebook|linkedin|twitter to see data from all three sources at once.

The Dot: .

The dot matches any single character - a letter, a number, or a symbol. It’s a simple wildcard.

Example: If you have URLs like product-A.html, product-B.html, and product-C.html, the pattern product-..html would match all of them, because the . acts as a placeholder for any character in that spot.

The Asterisk: *

The asterisk matches the preceding character zero or more times. It’s often used with the dot (.*) to say "match any number of any characters." This is great for handling dynamic text in a URL.

Example: Imagine your thank-you page URL includes a unique session ID, like /order/confirm?id=xyz123. By using .* you can make it work for everything by writing /order/confirm?id=.*, you'll match any URL that starts that way, regardless of what comes after.

GraphedGraphed

Still Building Reports Manually?

Watch how growth teams are getting answers in seconds — not days.

Watch Graphed demo video

Parentheses: ()

Parentheses are used to group characters together. They're often used with the pipe (|) to create more controlled "OR" conditions.

Example: To find traffic for blog posts that are about either social media or SEO, you could use a pattern like /blog/(social-media|seo)-.*. This will match any blog post URL starting with /blog/ that contains either "social-media" or "seo".

The Caret: ^

The caret matches the beginning of a string. This is extremely useful for specifying what a URL or campaign name starts with, ensuring you don’t accidentally match something that just contains your search term in the middle.

Example: If you want to filter for all of your blog pages, which live under /blog/..., you'd use ^/blog/. This will match /blog/my-first-post but won't match a page like /products/about-our-blog.

The Dollar Sign: $

The dollar sign is the opposite of the caret. It matches the end of a string. This is invaluable for ensuring your filter looks at the very end of your URL, preventing partial matches.

Example: You want to see traffic to your /contact page but filter out /contact/thank-you. Using the pattern /contact$ ensures that it only matches URLs that end exactly with /contact.

Square Brackets: []

Square brackets let you create a list of characters to match. For example, [xyz] will match "x", "y", or "z". You can also specify a range, such as [0-9] to match any single digit or [a-z] to match any single lowercase letter.

Example: Let's say you have an old-site.com that's known to send spam. When that's passed through GA page request, it can be /spam?from=old-site9, old-siteF, old-site3 etc. You could build a spam filter for your view filter that finds all URLs where a referring domain begins with /spam?from=old-site. In this case, [0-9] looks for any number, 0-9 but you would just enter this to grab all characters by expanding it, [A-Z0-9].*$, that you want to filter from old-domain.com.

The Backslash: \

The backslash "escapes" a special character, telling regex to treat it as a literal character instead of a command. This is essential when your URLs or search terms contain characters that have a special meaning in regex, like . or ?.

Example: Most sites use query parameters like ?source=facebook. If you want to match that question mark literally, you need to use a backslash before it, like this: \?source=facebook.

How to Use Regex in Google Analytics: Practical Walkthroughs

Regex can also be used throughout your property’s Administration settings, in areas that involve reporting (Segments, Goals, etc.).

Here are just a few great places where you can use what you just learned.

In the Admin area of the Google Analytics user interface, you can also use Regex for the following configurations (which apply pre-processing prior to data reporting):

Creating View Filters

View filters allow you to limit or modify data prior to making it available to use inside your property. Filters are permanent and will not process data retroactively.

Here’s an example: an IP filter to avoid populating your property and skewing your core advertising insights with internal GA sessions: You can use a Regex Filter for "IP Address" with a "Match" pattern using this Regex:

^66\.98\.237\.[5-9]$|^66\.98\.237\.[1-9][0-9]$|^66\.98\.237\.[1-2][0-9][0-9]

GraphedGraphed

Still Building Reports Manually?

Watch how growth teams are getting answers in seconds — not days.

Watch Graphed demo video

Segments

Regex opens plenty of other advanced tracking tactics: Segments also allow Regex filters, such as a case in which one user should be able to view certain data but not other sets of data for security purposes:

You can make a “Source Region Only” Custom Report with Regex with the following parameters configured if a US employee needs access to all user_id_dimension (a User ID custom-dimension you can implement beyond the client.id Google Analytics automatically populates for anonymous ad and web interaction) that contains “en-us,” but should have all access restricted to “nl-be,” (Netherlands-based user_id dimension value, for your brand that you wish should remain restricted.

You can simply use a Segment with this Regex pattern as your “Match Type Regex”: (.*us-en.*). A Regular expressions (Regex filter) you may wish to use may include or exclude some of the following filter statements:

  • Include User ID Dimension matches ([A-Z][A-Z]).*
  • Or, you can apply an exclude filter that follows the following pattern: nl-be which Exclude Regex.
  • For example, you could exclude 2 languages, too (one must use a (.*) statement in these types using regular expressions:

(.*de|nl.*)

This would exclude data where User ID Dimension (hit-level) matches, a regex for the previous statement you may choose an "Or" argument using an or |-separated list.

You may decide that “all upper-case countries, such as CN, BR, PL, must be kept hidden. You can try a statement like: Match Regular Expression Matches Regex: ([A-Z],[A-Z]) can hide a number of countries using only Regular Expression Matches Regex as your Custom Segment’s match type.

Pro-Tip: Regex does not only allow AND matches, OR, Not and statements are also supported and very useful.

You can use these (And, But or Not Regex) statements using this trick to negate and select as you wish.

And:

This can easily be done inside most places where a text field accepts inputs: just create an expression and use a period (.) that has Regex support using .* (a simple “And” Regex you could choose may state:

blue.*car.*

OR

This one is as familiar by now for what one would guess using only the | separates the values to make this match type’s input process easier to write for use cases with blue | car syntax.

GraphedGraphed

Still Building Reports Manually?

Watch how growth teams are getting answers in seconds — not days.

Watch Graphed demo video

Goal and Funnel Regex

Goals and funnel definitions for goals can make good use cases with advanced regular expressions. When you navigate over to Admin to “Define funnels,” any pages your visitors must hit sequentially prior to their completion, can more accurately exclude funnel entrances you do not wish to count, such as direct URLs or entrances. Regex enables you to track “must contain” or “only count” (or not, if you want!)

Regex is the perfect way to get a goal completion registered that can apply to more than one “Match Page Pattern” or URL fragment, you can use Regex to make an OR filter work.

This helps if you need to set up flexible goals without a URL string as the final destination. A Thank You URL might include something like: thank /you/username=Spencer_Williams.

An exact match would not catch this. So instead of a URL match-type goal like “contact/thankyou”, which is just that text, your new regex can catch this conversion goal page as it varies for each conversion by just writing something like: “thank*” (just be sure to select “Begins With…” as your selected choice). Any regular expression works just fine: “^contact/thank-you.*” can match anything following: /contact/thank.

For example a custom variable set in your “Goals.” may have a few page paths to your ‘order-completed,’ page:

  • /OrderConfirmation/order3435_4_vAR/ordercomplete.html
  • /OrderConfirmation/3436
  • Ordercomplete.
  • OrderConfirmation/html
  • /OrderConfirmation/3436
  • and

Order.complete, etc…"/order complete.html" is a fine filter, however... the filter might get more complicated with:

You can filter for multiple, similar “complete order” goals: with a little thought the funnel paths can become tighter:

(confirmation|complete)*order.*

Can match (confirmation OR a complete message after an order has gone through). You are not, with this regex statement required for one OR the other - you can now match both types of these completions for any given order using only a * to state “before or after is fine...it does not matter if someone sees *confirmation,* or complete’.

This means any page that starts with /confirmation can catch your conversions for more accurate goal tracking. Regex statements make this easier.

Don't Confuse Regular Expressions with Operators

One of the quickest paths to confusing yourself, making data management much more complex than what’s required, is using an “Exactly Matching” Operator. When not necessary Regular Expressions can replace complex formulas.

Just Remember: Regex can seem very complicated if you have never tried, and even if you had, one is going to likely require further reading to see more of this language at use: the learning can take longer and longer if you don’t find something Regex-related to make simple and easy, at scale – but this is why a more intuitive solution may be a simpler path: after you get how powerful regular expressions are to manage custom data views (at scale) you no longer want them.

Final Thoughts

Regex opens up a whole new level of analysis in Google Analytics, transforming it from a simple reporting tool into a flexible, powerful analysis platform. By learning a few basic regular expressions, you can save massive amounts of time, create more accurate filters, and uncover insights that just aren't possible with default settings.

While mastering Regex is a fantastic skill, we created Graphed because we knew there had to be an even easier way. Instead of writing and testing Regular Expressions, you can just ask questions in plain English. Connect your Google Analytics account, and then ask, "Show me all traffic from Facebook, Instagram, and Twitter this month," and Graphed instantly builds the report for you - no Regex required.

Related Articles