Home / Free tools

Free tool

GA4 and GTM regex tester

Type an expression and the values it should catch, one per line: page paths, URLs, hostnames or event names. Each value is tested as GA4 reads a regex (the whole value, case sensitive) and as a GTM trigger condition does (anywhere in the value), and anything RE2 does not accept is flagged before it runs.

Examples:

Also free: GTM container viewer · Tracking request decoder

Full match in GA4, contains in GTM

The same expression gives different answers in the two products. Google’s help for GA4 puts it plainly: “By default, Google Analytics Regex is full regex and case sensitive.” The expression has to describe the whole value. Google’s example uses the City dimension: San Francisco returns only San Francisco, and .*San Francisco.* is what it takes to also catch a longer name with San Francisco inside it. That applies wherever GA4 takes a regex: data filters, key events, segments, audiences, content groups and custom channel groups.

A Tag Manager trigger condition with matches RegEx works the other way round in Google’s own example: /pro/ matches every page with “pro” in the path. The expression is looked for anywhere in the value. So /checkout as a GA4 page path condition matches one page, and as a GTM trigger it also fires on /checkout/thanks and /en/checkout. To pin a GTM condition to one exact value, start it with ^ and end it with $; in GA4 those two change nothing.

The tester shows both answers for every value, so a line that reads “GA4: no, GTM: yes” is a value that contains a match without being one. Values are tested case sensitive.

What RE2 leaves out

GA4’s help links to the RE2 syntax for what an expression may use, and RE2 does not support these:

An expression copied from a JavaScript or PCRE tester often carries one of these, most often a negative lookahead to exclude a page. The tester reports each one with its position and runs nothing, because the browser’s own engine would accept it, and its answer would not tell you what GA4 does. To exclude, add a second condition that excludes; in GTM that is a does not match RegEx row on the same trigger.

RE2 also has syntax JavaScript lacks, and the tester translates it before running: \A and \z for the start and end of the value, named groups written (?P<name>…), \Q…\E for literal text, POSIX classes such as [[:digit:]], and a flag such as (?i) at the very start. A flag in the middle of an expression has no JavaScript form, so it is reported as not testable instead of guessed.

The 1000 repetition limit

RE2 rejects the counting forms x{n}, x{n,} and x{n,m} when either count is above 1000. [0-9]{1000} is accepted; [0-9]{1001} is not, and the tester says so.

Mistakes it points out

A catch-all such as .* in a Custom Event trigger matches more than the events you push: why a wildcard trigger started firing on gtag config calls.

To see which regex conditions a published container uses, open it in the GTM container viewer: it lists every trigger as its conditions.

Questions

Does a GA4 regex match part of a value?

No. Google’s help for GA4 says its regex is full match and case sensitive by default: the expression has to describe the whole value. San Francisco matches only the value San Francisco. For a partial match, add .* at the start and the end: .*San Francisco.* matches any value with San Francisco in it.

Why does my GTM regex trigger fire on pages I did not expect?

In Google’s own example for a trigger condition, /pro/ with matches RegEx covers every page with /pro/ anywhere in the path. The expression is looked for inside the value, so /checkout also matches /checkout/thanks and /en/checkout. Put ^ at the start and $ at the end when the value has to be exactly that.

Can I use a lookahead or lookbehind in GA4?

No. GA4’s help points to the RE2 syntax, and RE2 does not support lookahead, lookbehind, backreferences, possessive quantifiers or atomic groups. To exclude something, use a second condition that excludes it instead of (?!…) inside one expression.

How do I make a GA4 regex ignore case?

Put (?i) at the very start of the expression. RE2, whose syntax GA4’s help links to, reads it as ignore case for the rest of the expression. This tester applies it when it is at the start; flags placed anywhere else are reported rather than guessed.

Is what I type sent anywhere?

No. The expression and the values are tested in your browser and never put in the page address.

Try it on your own site

Tag Master is free, needs no account, and collects no data.

Add to Chrome, it’s free