GA4 supports regex (regular expressions) in report filters, explorations, and audiences — but the documentation is thin, the syntax is inconsistent across features, and many patterns that worked in Universal Analytics simply don't work in GA4. Here's your definitive reference.
Where Regex Works in GA4
GA4 exposes regex in five places, but support is inconsistent. Explorations, custom report filters, audience definitions, and Exploration segments all accept a "matches regex" operator with full RE2 syntax. Standard reports in the main GA4 interface are more limited — comparisons only offer "contains" or "exactly matches," so you cannot use regex there.
- Explorations (Free-form, Funnel, Path): Filter rows using "matches regex" ✅
- Custom report filters: "matches regex" operator available ✅
- Audiences: Regex conditions on dimensions ✅
- Exploration segments: Full regex support ✅
- Standard report comparisons: No regex — "contains" or "exactly matches" only ❌
If you need regex-style filtering in a standard report, switch to an Exploration or build a Looker Studio report against the same data source.
GA4 Regex Syntax Rules (RE2, Not PCRE)
GA4 uses Google's RE2 regex engine, the same engine used in BigQuery and Go. RE2 is guaranteed linear time, which is safer than PCRE but strips out several features most developers expect. Patterns copied from JavaScript, Python, or Universal Analytics will often fail silently — the filter returns zero rows with no error message.
- No lookaheads or lookbehinds:
(?=...)and(?<=...)are rejected. - No backreferences:
\1,\2etc. are not supported. - Case sensitive by default: prefix with
(?i)for case-insensitive matching. - Partial match by default: the pattern matches any substring. Use
^and$to anchor for a full match. - Escape special characters: dots, parentheses, question marks, and plus signs all need a backslash.
Copy-Paste Regex Patterns for Common GA4 Filters
These six patterns cover roughly 80% of real-world GA4 filtering needs. All of them are RE2-compatible and have been tested inside Exploration filters and audience definitions.
Match multiple page paths:
^/(blog|resources|guides)/
Matches any page starting with /blog/, /resources/, or /guides/.
Exclude specific pages:
^/(admin|internal|staging)
⚠️ RE2 has no negative lookahead. Use this pattern with the "does not match regex" operator instead of trying to invert the match inline.
Match UTM campaign patterns:
(?i)^(spring|summer|fall|winter)_sale_2025$
Case-insensitive match for seasonal campaign names, anchored so "spring_sale_2025_final" wouldn't match.
Match product category pages only:
^/products/[^/]+/?$
Matches /products/shoes/ and /products/bags, but NOT /products/shoes/nike/ — useful for isolating top-level category performance.
Match localized pages:
^/(en|sv|de|fr)/
Matches pages with language prefixes — a faster alternative to creating four separate audiences.
Using Regex in Explorations: Step-by-Step
Explorations are where regex is most useful in GA4. They give you a flexible canvas to filter events, sessions, or users by any dimension, with the regex applied at query time. Results refresh in seconds even on large datasets because filtering happens in BigQuery under the hood.
- Open GA4 and navigate to Explore → Blank to create a new Free-form Exploration.
- Drag your target dimension (e.g., "Page path and screen class") into Rows.
- Click the filter icon at the top of the dimension column.
- Change the match type from "exactly matches" to "matches regex".
- Paste your RE2 pattern and hit Apply.
- The exploration updates instantly to show only rows where the dimension matches.
Save the exploration once it's working — you can reuse the regex filter across multiple reports without retyping it.
Using Regex in Audience Definitions
Regex in audiences lets you build dynamic segments that automatically include new matching users as they appear — no need to rebuild the audience when you add a new product category or campaign. Audiences created this way populate retroactively up to 30 days and continue to grow for up to 540 days depending on your GA4 retention setting.
- Go to Admin → Audiences → New Audience → Create a Custom Audience.
- Add a condition on a dimension (e.g., Page path and screen class).
- Set the operator to "matches regex (case sensitive)" or the case-insensitive variant.
- Enter your RE2 pattern and set membership duration (30-540 days).
- Preview the audience size before saving — GA4 shows estimated users over the last 30 days.
Example pattern for "any product page visitor": ^/products/. This builds an audience of every user who visited any URL under /products/, perfect for remarketing in Google Ads.
Common Regex Mistakes That Silently Break GA4 Filters
When a GA4 regex filter returns zero rows, the report shows "No data available for this time range" with no hint that the regex itself is the problem. These are the four failure modes we see most often when auditing client GA4 accounts.
- Forgetting anchors:
blogmatches "/blog" but also "/blogging-tips" and "/weblog". Use^/blog/for precision. - Not escaping dots:
google.commatches "googleXcom" too, because the dot is a wildcard. Usegoogle\.com. - Using lookaheads: RE2 rejects them silently. Use the "does not match regex" operator with a positive pattern instead.
- Over-complicating patterns: Start simple. Test with three or four known URLs in an Exploration before rolling the pattern into a production audience or filter.
Filter Accuracy Check
NiceLookingData verifies your GA4 data filters and configurations to ensure you're capturing — and not accidentally excluding — the data you need. Run a free audit.
Run a free GA4 audit on your property
Connect your Google Analytics 4 property. Our auditor runs 58 checks and gives you an instant health score with a plain-English action plan.
