Advertisement

GA4 Regex Not Working? Diagnose It in 60 Seconds

The pattern works in your IDE, in Notepad, in the tester — and GA4 returns zero rows, refuses to save the filter, or shows rows you never asked for. Those are three different failures with six different causes. This page splits them in one step and gives you a failing pattern → fixed pattern pair for every one.

TL;DR: copy one real dimension value out of GA4, paste it into the tester with your pattern, and read the branch: doesn't match there either → full-match, dimension or case (symptom A). GA4 rejects the pattern outright → RE2 syntax (symptom B). matches rows you didn't want → escaping or precedence (symptom C).

1. First, the 60-second triage

Do not start by rewriting the pattern — that usually produces a second broken pattern. Start by copying one exact value from the GA4 table that should have matched (right-click the cell → copy, so invisible characters come along) and pasting it into the tester beside your pattern:

  1. Open the regex tester and paste your pattern untouched.
  2. Paste the real dimension value underneath it.
  3. Read the branch in the table below and jump to that section.
What you see in GA4What it meansFix in
Filter saves, but 0 rows (and no error)The pattern never covers the whole value, the dimension is wrong, or the case is offSymptom A
Filter is rejected / won't save, or the field turns redThe engine is RE2 — the construct does not exist thereSymptom B
Rows appear you did not intendUnescaped dot, greedy .*, alternation precedence, or a literal | inside a classSymptom C

One trap in this triage: the tester matches like JavaScript — a search anywhere in the string — while GA4's matches regex is a full match. So "matches here, zero rows in GA4" is the classic full-match signature, not a broken pattern. Anchor it as ^pattern$ in the tester to preview GA4's verdict exactly. Full background on matches regex vs partially matches regex.

2. Symptom A — the filter saves but returns zero rows

Nothing is broken; GA4 simply never saw a complete match. Three causes, in the order they actually happen in real accounts:

Cause 1 — full-match semantics (the missing .*)

GA4's matches regex must cover the entire value, and the dimension you filter is usually the full URL, not the path you had in mind. Writing ^/blog/post-1$ against page_location therefore matches nothing, because the value starts with https://….

What you wroteDimension valueResult
^/blog/post-1$ https://site.com/blog/post-1 No match Try →
.*\/blog\/post-1$ https://site.com/blog/post-1 Match Try →

Fix: lead with .* (or drop the anchors and use the partially matches regex option where the surface offers it). See the page path regex guide for the dimension-by-dimension versions.

Cause 2 — wrong dimension

page is not a GA4 dimension. Depending on the report you get page_path (Page path), page_path+query_string (Page path and query string), page_location (Page location, full URL) or page_title. Filter a pattern built for one against another and it silently matches nothing — a path pattern against page_location is cause 1 again, and a full-URL pattern against page_path can never match. Pick the dimension first, then the pattern.

Cause 3 — case sensitivity, and values that aren't what they look like

What you wroteDimension valueResult
^/Checkout/.*$ /checkout/thanks No match Try →
^/[Cc]heckout/.*$ /checkout/thanks Match Try →
^/blog/.*$ (not set) No match Try →
^(/blog/.*|\(not set\))$ (not set) Match Try →

GA4's documented filter surfaces are case sensitive, so /Checkout/ never sees /checkout/thanks — write [Cc]heckout, or (?i) where the surface accepts it. (Custom channel-group conditions are the exception: they are case-insensitive — covered in the channel grouping guide.) Two more silent row-killers while you are here: invisible characters — copy the value from GA4 instead of retyping it, an en-dash or trailing space in /blog/post-1 breaks an anchored pattern — and (not set) rows, where the parameter was never sent, so no path pattern will ever catch them. Parenthesise and escape as shown above if you need those rows.

Check the pattern against the real value first
Paste the exact GA4 value into the tester, anchor the pattern with ^ and $, and only then touch the filter.
Open the regex tester →

3. Symptom B — GA4 rejects the pattern

GA4 runs RE2, a linear-time engine that deliberately leaves out every construct that needs backtracking. Unsupported syntax is rejected outright — no partial match, no warning about which fragment broke. The tester runs JavaScript, which does support these constructs, so a pattern can look perfectly healthy here and be dead on arrival in GA4. That mismatch is the whole bug.

You wrote (PCRE habit)In the testerIn GA4 (RE2)RE2-safe replacement
checkout(?=/thanks) Match Rejected /checkout(/thanks)? Try →
(?<=/)(\w+) Match Rejected /(\w+) Try →
/checkout(/thanks)? Match Accepted — Try →

The complete unsupported list with a replacement for each — negative lookahead, backreferences, atomic groups, possessive quantifiers, conditionals, recursion, \K — is on the RE2 vs PCRE page. The two you will actually hit in GA4:

  • Lookahead / lookbehind → include the surrounding text in the pattern, or capture it: foo(?=bar) becomes foobar, or (foo)bar if you need group 1.
  • "Contains X but not Y" → you cannot express it in one RE2 pattern. Use two filters — one include, one exclude — instead of a negative lookahead.

4. Symptom C — it matches too much, or the wrong rows

Every row below matches more than the author intended. Same engine, same input — only the pattern changes.

MistakeWhat you wroteInputResult
Unescaped dot — . means any character .*.pdf$ /downloads/reportXpdf Match (wrong) Try →
Escape the dot .*\.pdf$ /downloads/reportXpdf No match (correct) Try →
Alternation precedence — ^/blog|/news$ parses as (^/blog)|(/news$) ^/blog|/news$ /blog-tracking Match (wrong) Try →
Parenthesise every alternation ^(/blog|/news)$ /blog-tracking No match (correct) Try →
| inside a class is a literal pipe — one character from the set [blog|news] /about Match (wrong) Try →
Alternation belongs outside the brackets (/blog|/news) /about No match (correct) Try →

The other half of symptom C is the greedy .*: in ^/blog/.* the wildcard happily eats everything to the end of the value, so a pattern meant to capture a segment swallows the query string too. Make it lazy (.*?) or bound it ([^?]+) when you need the part, not the whole. The GA4 regex cheat sheet has ready-made, already-escaped patterns for the common jobs.

5. Why the same pattern behaves differently per screen

This is the least obvious cause of "it worked yesterday": two GA4 screens, two match rules. GA4 regex match types maps the full matrix; this is the working summary.

SurfaceRegex match typesBehaviour to assume
Explorations (Free form filters)matches regex / does not match regexFull match only — wrap with .*
Segments & audiencesmatches regex / does not match regexFull match only
Create / modify eventsmatches regex on names & parametersFull match only
Standard report filters (+ Add filter)full & partialCase sensitive, capped at 250 characters
Custom channel groupsfull & partialCase-insensitive; rules are fixed, so edit a custom group
GA4 Data APIFULL_REGEXP / PARTIAL_REGEXPPick the right match type in the request
BigQuery REGEXP_CONTAINSsubstring matchRE2, but contains-semantics — no .* needed

Rule of thumb: if the screen only offers matches regex, write the full-match form. The extra wildcards are harmless on screens that also offer partial matching, so one pattern works everywhere.

6. The 5-minute QA ritual before you save

  1. Anchor it. Run ^pattern$ in the tester against a real value — that is GA4's full-match verdict, not JavaScript's partial one.
  2. Shrink it. Delete half the pattern; if the result does not change, that half was never doing the work. This isolates the offending fragment in two steps.
  3. Count it. Decide the expected row count before applying the filter — "these 14 checkout sessions" — then compare. A filter that matches "some rows" has told you nothing.
  4. Check RE2. No lookahead, no lookbehind, no \1, no atomic groups — if in doubt, RE2 vs PCRE has the replacement table.
  5. Check the dimension and the case. Right dimension (page_path vs page_location), and every literal letter cased exactly as GA4 sends it — or bracketed [Cc]heckout.

Filters apply at query time, so the corrected pattern shows up in the very next report refresh — no reprocessing, no waiting. If the count is still wrong after all five steps, the pattern is fine and the data is not: check for (not set) rows and untagged traffic in the Unassigned traffic fix walkthrough.

Reproduce the failure in 10 seconds
Paste the failing pattern and the exact GA4 value side by side — the highlighted match tells you which of the six causes you have.
Open the regex tester →

FAQ

Why does my regex work in the tester but return nothing in GA4?

Two reasons. GA4 full-matches by default, so a substring match in the tester can cover zero of the whole dimension value — wrap it as .*pattern$. And the tester runs JavaScript while GA4 runs RE2: a construct RE2 rejects (lookahead, lookbehind, backreferences) matches happily here and never saves in GA4.

Why does GA4 say my regular expression is invalid?

RE2 does not support lookahead, lookbehind, backreferences, atomic groups, possessive quantifiers or recursion. Swap in the recipe from RE2 vs PCRE: foo(?=bar) → foobar (or a capture group), (foo|bar)\1 → foofoo|barbar, and "contains X but not Y" → two filters instead of a negative lookahead.

Is GA4 regex case sensitive?

Yes on the documented filter surfaces — /Checkout/ never matches /checkout/. Write [Cc]heckout, or use (?i) where the surface accepts inline flags. Custom channel-group conditions are the documented exception and match case-insensitively.

Why does my GA4 filter match more rows than I expected?

Escaping or precedence: an unescaped . matches any character, a greedy .* swallows the rest of the value, ^/a|/b$ parses as (^/a)|(/b$), and | inside square brackets is a literal pipe. Anchor both ends and parenthesise the alternation: ^(a|b)$.

Related on RegexLab: GA4 regex match types (full vs partial per screen), RE2 vs PCRE (every unsupported construct + fix), the GA4 regex cheat sheet, the page path regex guide, the exclude page path regex (does-not-match patterns that actually hide rows), the custom channel grouping guide and the Unassigned traffic fix. For ready-made patterns beyond GA4 (dates, emails, URLs, IPs, UUIDs, log lines and more), browse the regex pattern library.

RegexLab — a free, private, browser-based regex tester. No data leaves your device.

Regex matching uses your browser's native JavaScript RegExp engine. Ads fund this free tool.