Advertisement

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)

Page path & URL regex for GA4

Use these with the page_path (or the path part of page_location) dimension.

What you wantRegex
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.*\.htmlTry in tester →
Landing page starts with /promo/promo/.*Try in tester →

Event name regex for GA4

Match against the event_name dimension.

What you wantRegex
Exactly page_viewpage_viewTry in tester →
Any event starting with select_select_.*Try in tester →
Any event ending in _click.*_clickTry 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 eventsscrollTry in tester →

Traffic source & medium regex

Match against session_source / session_medium (or campaign fields).

What you wantRegex
Source is GooglegoogleTry in tester →
Medium is organicorganicTry 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 wantRegex
Title contains "GA4".*GA4.*Try in tester →
Title starts with "Free"Free .*Try in tester →
Title ends with "— RegexLab".*RegexLabTry in tester →

RE2 replacements: what to use instead of lookahead

RE2 can't use assertions, but you rarely need them in GA4:

Test any of these before you paste them into GA4
Free, private, runs entirely in your browser — no data leaves your device.
Open the GA4 regex tester →

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.