If you ever pasted a regex into Google Analytics 4 and got zero rows back
while the exact same pattern works fine in your editor — you didn't write a
"wrong" regex. You wrote one that GA4 doesn't run the same way.
Two differences explain almost every failure.
1. GA4 matches the whole string
GA4's regex condition is a full match, not a "contains".
/blog/
- In most regex engines, this finds
/bloginside/blog/ga4-guide. - In GA4, it matches only the exact string
/blog./blog/ga4-guide→ zero rows.
Fix — wrap it:
/blog/.* → everything under /blog/
.blog. → any path containing "blog"
- GA4 uses RE2 — no lookahead, no backreferences
GA4 runs Google's RE2 engine: fast and safe, but it does not support:
- lookahead
(?=…)/(?!…) - lookbehind
(?<=…)/(?<!…) - backreferences
\1
A pattern like ga4(?=-tips) fails silently. And because RE2 can't assert,
"match X but not Y" logic is better expressed as two filters in GA4 itself
(one include, one exclude) instead of one clever regex.
Patterns that actually work in GA4
| You want | Regex |
|---|---|
| Pages under /blog/ | /blog/.* |
Product detail /products/<slug>
|
/products/[^/]+ |
Event ending in _click
|
.*_click |
| Source is google or bing | |
| URLs with a query string | {% raw %}.*\?.* (use page_location, not page_path) |
Test before you paste
Every pattern above can be checked live against sample data in a free,
browser-only tester — no login, and no data ever leaves your device:
- Tester: https://regextester.site/
- Cheat sheet, 25+ ready-made GA4 patterns: https://regextester.site/ga4-regex-cheatsheet/
Both run entirely client-side, so what matches in the tester matches in GA4.
Top comments (0)