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 and How to Use Regex in GA4
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" — supported
- Custom report filters: "matches regex" operator available — supported
- Audiences: Regex conditions on dimensions — supported
- Exploration segments: Full regex support — supported
- 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: RE2 Rules and Limitations
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.
GA4 gives you no error message when a pattern is malformed — it just silently returns zero rows. Build and check your expression somewhere that shows you the match before it touches a live filter or audience. NiceLookingData's free GA4 & GTM Regex Tester validates RE2 syntax and highlights matches right in your browser — nothing is sent to a server.
Practical Regex Patterns and Recipes
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)
Note: 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. If you're auditing an inconsistent UTM set in the first place, the free UTM builder lints casing drift before campaigns ever launch.
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.
Applying Regex in Explorations and 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 Mistakes and How to Avoid Them
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.
Frequently Asked Questions
What are GA4 regex filters?
GA4 regex filters let you match dimension values against a regular expression pattern rather than an exact string or simple contains check. You use them inside Explorations, custom report filters, audience definitions, and Exploration segments. The "matches regex" operator tells GA4 to evaluate your pattern against each value in the selected dimension and return only rows where the pattern finds a match. Because GA4 uses partial matching by default, you don't need to match the entire string — but you should anchor patterns with ^ and $ when precision matters.
Where can I use regex in GA4?
Regex is available in four places: Explorations (free-form, funnel, and path reports), custom insight filters, audience definitions, and Exploration segments. Standard reports in the main GA4 interface do not support regex — comparisons there are limited to "contains" or "exactly matches." If you need regex-style filtering in a standard report, the practical workaround is to replicate the report as an Exploration or connect Looker Studio to the same property and apply the filter there.
How do I filter by multiple values in GA4 using regex?
Use the pipe character | as an OR operator inside your pattern. For example, to match page paths under /blog/, /guides/, or /resources/, write ^/(blog|guides|resources)/. The parentheses group the alternatives and the caret anchors the match to the start of the string. There is no practical limit to the number of alternatives you can chain with pipes, though very long patterns can become hard to read and debug — consider splitting them across multiple filter rows joined with AND/OR logic if the pattern exceeds five or six alternatives.
Does GA4 use Perl-compatible regex (PCRE)?
No. GA4 uses Google's RE2 engine, not PCRE. The practical difference is that RE2 does not support lookaheads ((?=...)), lookbehinds ((?<=...)), or backreferences (\1). Patterns copied from JavaScript, Python, PHP, or Universal Analytics that rely on these features will either be rejected outright or silently return zero results in GA4. RE2 does support character classes, quantifiers, alternation, anchors, and case-insensitive mode via the (?i) prefix — the vast majority of day-to-day analytics filtering is achievable within those constraints.
How do I exclude internal traffic using regex in GA4?
The standard approach is to filter by IP address using GA4's built-in internal traffic rules rather than regex. Go to Admin → Data Settings → Data Filters → Internal Traffic and define your office IP ranges there, then activate the filter. For cases where you need regex exclusion inside an Exploration or audience, GA4 provides a "does not match regex" operator — write a pattern that identifies the traffic you want to remove (for example, matching a specific hostname or URL path used only by your team) and apply the "does not match" variant. RE2 has no inline negation syntax, so the operator itself is the only way to exclude matches.
What is the difference between GA4 filters and segments?
Filters apply to report rows at query time — they narrow down which dimension values appear in a table or chart, but they don't change what users or sessions are counted. Segments, on the other hand, define a subset of users, sessions, or events and apply that subset to the entire Exploration scope. A regex filter on page path will hide rows for pages that don't match, but the session count in the corner still reflects all sessions. A session segment built with the same regex will recalculate every metric — sessions, users, conversions — as if only those matching sessions existed. Use filters for table-level row filtering; use segments when you need a true cohort comparison.
How do I test a regex filter in GA4?
The fastest way is to create a blank Exploration, drag in the dimension you want to filter (for example, "Page path and screen class"), then add a filter with "matches regex" and your pattern. If the table returns rows you expect, the pattern works. If it returns zero rows, check four things: whether the dimension values you're trying to match actually exist in the selected date range, whether you need anchors (^ or $) that are too strict, whether special characters like dots need escaping, and whether the pattern uses any RE2-unsupported syntax like lookaheads. For audience regex, use the audience preview panel — it shows estimated user count for the last 30 days before you save.
What are common GA4 regex patterns for analytics?
A handful of patterns cover most real-world filtering needs. To match multiple page sections: ^/(blog|guides|resources)/. To match a single top-level URL category and all its children: ^/products/. To match a localized site structure: ^/(en|sv|de|fr)/. To match an exact page: ^/thank-you/?$ (the ? makes the trailing slash optional). To match product pages without subcategories: ^/products/[^/]+/?$. To match campaign names case-insensitively: (?i)black_friday. All of these are RE2-compatible and work in Explorations, audience definitions, and custom report filters.
Analytics consultant turned founder. After years running the same GA4 and GTM audits across client engagements, Ludde built the audit into a product — so the pattern-matching takes a minute, not a meeting. More about Ludde →
Run a free GA4 audit.
Connect your Google Analytics 4 property. Our auditor runs 61 checks and gives you an instant health score with a plain-English action plan.
