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:
- Open the regex tester and paste your pattern untouched.
- Paste the real dimension value underneath it.
- Read the branch in the table below and jump to that section.
| What you see in GA4 | What it means | Fix in |
|---|---|---|
| Filter saves, but 0 rows (and no error) | The pattern never covers the whole value, the dimension is wrong, or the case is off | Symptom A |
| Filter is rejected / won't save, or the field turns red | The engine is RE2 — the construct does not exist there | Symptom B |
| Rows appear you did not intend | Unescaped dot, greedy .*, alternation precedence, or a literal | inside a class | Symptom 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 wrote | Dimension value | Result | |
|---|---|---|---|
^/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 wrote | Dimension value | Result | |
|---|---|---|---|
^/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.
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 tester | In 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)becomesfoobar, or(foo)barif 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.
| Mistake | What you wrote | Input | Result | |
|---|---|---|---|---|
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.
| Surface | Regex match types | Behaviour to assume |
|---|---|---|
| Explorations (Free form filters) | matches regex / does not match regex | Full match only — wrap with .* |
| Segments & audiences | matches regex / does not match regex | Full match only |
| Create / modify events | matches regex on names & parameters | Full match only |
| Standard report filters (+ Add filter) | full & partial | Case sensitive, capped at 250 characters |
| Custom channel groups | full & partial | Case-insensitive; rules are fixed, so edit a custom group |
| GA4 Data API | FULL_REGEXP / PARTIAL_REGEXP | Pick the right match type in the request |
BigQuery REGEXP_CONTAINS | substring match | RE2, 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
- Anchor it. Run
^pattern$in the tester against a real value — that is GA4's full-match verdict, not JavaScript's partial one. - 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.
- 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.
- Check RE2. No lookahead, no lookbehind, no
\1, no atomic groups — if in doubt, RE2 vs PCRE has the replacement table. - Check the dimension and the case. Right dimension (
page_pathvspage_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.
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.