GA4 Regex Cheat Sheet — 25+ Google Analytics 4 Patterns That Actually Work
A copy-paste library of Google Analytics 4 regex patterns for page paths, event names, traffic sources and page titles — each one tested against the exact RE2 engine GA4 uses. Click Try in tester on any row to load it into a free, private GA4 regex tester.
Why GA4 regex "doesn't work" for most people: GA4 uses full-match semantics (your pattern must cover the whole string) and the RE2 engine (no lookahead, no backreference). Learn these two rules below and almost every "regex not working in GA4" problem disappears.
How GA4 actually uses regex (read this first)
- Full match, not contains. In standard reports, explorations and audiences, a regex condition must match the entire value.
/blog/does not match/blog/post-1. To match a substring, wrap it:.*blog.*. - RE2 engine. GA4 runs Google's RE2, which is fast and safe but does not support lookahead/lookbehind or backreferences.
(?=…),(?!…),(?<=…)and\1will fail silently. - Case-sensitive in filters.
ga4will not matchGA4. Use explicit alternation like(?:[Gg][Aa]4)when casing varies.
Page path & URL regex for GA4
Use these with the page_path (or the path part of page_location) dimension.
| What you want | Regex | |
|---|---|---|
Everything under /blog/ | /blog/.* | Try in tester → |
Product detail /products/<slug> | /products/[^/]+ | Try in tester → |
| Homepage only | / | Try in tester → |
| Any path with 2 segments | /[^/]+/[^/]+ | Try in tester → |
| Path contains "checkout" | .*checkout.* | Try in tester → |
Language prefix /en/ or /id/ | /(en|id)/.* | Try in tester → |
| HTML pages only | .*\.html | Try in tester → |
| Landing page starts with /promo | /promo/.* | Try in tester → |
Event name regex for GA4
Match against the event_name dimension.
| What you want | Regex | |
|---|---|---|
Exactly page_view | page_view | Try in tester → |
Any event starting with select_ | select_.* | Try in tester → |
Any event ending in _click | .*_click | Try in tester → |
view_item OR view_cart | (view_item|view_cart) | Try in tester → |
| Any ecommerce conversion | (add_to_cart|begin_checkout|purchase) | Try in tester → |
| Scroll events | scroll | Try in tester → |
Traffic source & medium regex
Match against session_source / session_medium (or campaign fields).
| What you want | Regex | |
|---|---|---|
| Source is Google | google | Try in tester → |
| Medium is organic | organic | Try in tester → |
| Source Google or Bing | (google|bing) | Try in tester → |
| Source contains "instagram" | .*instagram.* | Try in tester → |
| Paid campaigns (cpc / ppc / paid) | (cpc|ppc|paid) | Try in tester → |
Page title regex
Match against the page_title dimension.
| What you want | Regex | |
|---|---|---|
| Title contains "GA4" | .*GA4.* | Try in tester → |
| Title starts with "Free" | Free .* | Try in tester → |
| Title ends with "— RegexLab" | .*RegexLab | Try in tester → |
RE2 replacements: what to use instead of lookahead
RE2 can't use assertions, but you rarely need them in GA4:
foo(?=bar)(foo followed by bar) → just matchfoobar, then trim the match logic or use a second condition.(?<=prefix)suffix→ RE2 has no lookbehind. Split into two GA4 conditions joined by AND, or match the whole string explicitly.\1backreference → not supported. Re-express the repeated structure with a character class (for example(\w+)-\w+) instead of referring back.
FAQ
Does GA4 regex support lookahead or lookbehind?
No. GA4 uses RE2, so (?=…), (?!…), (?<=…) and (?<!…) are not supported. Rewrite without assertions or split the condition in two.
Why does my regex not match in GA4?
Because GA4 uses full-match semantics. The pattern must match the entire value. /blog/ won't match /blog/post — use .*blog.* to match a substring.
Is GA4 regex case-sensitive?
Yes, in filters it is case-sensitive. To match any casing, use a character class such as (?:[Gg][Aa]4).
Every pattern above runs on your browser's native JavaScript RegExp engine, which is RE2-compatible for these constructs — so if it matches in the tester, it will match in GA4.