GA4 Segment Regex - Build Segments & Audiences That Match
You want one segment or audience that catches a set of values - all blog pages, all AI referrals, all checkout steps - and you reach for regex in the condition builder. This page takes you from that wish to a saved segment or audience that returns the right rows: which feature you are actually building (segment, audience, channel group), how scope changes what your pattern even sees, the full-match operator rule, six copy-paste recipes with live try-links, and the audience-only semantics (membership duration, triggers, refresh lag) that make an audience behave nothing like a segment.
TL;DR: Segments and audiences accept matches regex / does not match regex in full match - your pattern must cover the entire value, so wrap it in .* for partial behavior (Google's regex doc: GA is full regex and case sensitive by default). Scope decides the pattern: the same ^/(blog|checkout)(/.*)?$ answers three different questions as an event, session, or user segment (2 events vs 4 events vs all 6 in our example below). A segment is a retroactive Explore filter; an audience is a membership list with entry rules, a 540-day cap, 24-48h refresh lag and triggers. Test each recipe in the tester before you save.
1. Segment vs audience vs channel group - which one changes what
Before the pattern, pick the feature - they change different things, and mixing them up is why "my regex works but my numbers don't".
| Feature | What it is | When it changes past data | Lives where |
|---|---|---|---|
| Segment | A set of conditions that filters data in an exploration - no membership logic, fully retroactive | Immediately: it is a query-time filter, so any date range you query is filtered the same way | Explore only (10 per exploration, 50 saved per property) |
| Audience | A group of users who meet your conditions - users enter and exit over time | Never retroactively: an audience accumulates from the moment you save it (Google Ads copies get up to 30 days of backfill) | Admin > Data display > Audiences; reports, explorations, Google Ads (100 per property) |
| Channel group | A grouping rule applied when a report is computed (source/medium → channels) | Yes: saved rules re-sort past sessions into the new groups immediately | Reports, explorations, and as a dimension in audience conditions |
Two consequences worth internalizing. First, the same conditions give different user counts in a segment vs an audience - Google documents this as intentional: the segment filters whatever you query, the audience is membership evaluated over time. Second, raw hit data never changes: source/medium values and stored page paths are immutable, so a regex in a segment or audience only changes what a view shows. For the same reason, custom channel group rules re-sort history the moment you save them (see the Unassigned traffic guide for that contrast in practice).
2. Scope decides the pattern: user / session / event
A segment or audience condition is evaluated at a scope: within the same event, within the same session, or across all sessions (user). Audience conditions use the same three. The scope does not change your regex - it changes what your regex is asked about, and therefore which rows come back. Same pattern, one user, three sessions over two days:
| Scope | Question it answers | What the regex sees | Rows back |
|---|---|---|---|
| Event | Which events happened on a blog or checkout page? | Each event's own page_location alone | 2 events - /blog/post-a, /checkout |
| Session | Which sessions touched a blog or checkout page? | Every event inside a session where at least one event matched | 4 events - all of s1 + s2 (s3 never matched, so its /pricing and /about are out) |
| User | Did this person ever touch a blog or checkout page? | All of the user's events, once any one of them matched | All 6 events - the qualifying user's entire history in range |
Three scopes, three answers, one pattern. Practical reading: use an event scope to count the matching hits themselves, a session scope to characterize journeys ("sessions that included checkout"), and a user scope for "people who ever did X" - where the qualifying user's non-matching events are pulled in too, which is usually what you want for audience building and usually not what you want for counting pages. Condition groups add AND/OR on top (groups are AND-ed; within a group you can combine AND or OR), and sequences let you require an order - but scope is the first fork, decide it before you write the pattern. For which dimensions exist at which scope, see the page path regex guide and the event filter guide.
3. The operator: full match, and converting partial to full
In the segment and audience condition builder you get matches regex and does not match regex - full match: the pattern must consume the entire value. Google's regex doc states it directly: GA regex is full regex and case sensitive by default, and partial matching "requires the user to add metacharacters". There is no partial option to fall back on here (standard report filters and channel groups do offer partially matches regex - the full surface map lives on the regex match types page, which this page does not repeat).
| You want | Write | Example (full match) | Try |
|---|---|---|---|
| Exact value | ^value$ (or plain value) | San Francisco matches only San Francisco, not South San Francisco | Try → |
| "contains" behavior | .*value.* | .*San Francisco.* matches both | Try → |
| Starts with | ^prefix.* | ^/blog.* on /blog/post-a | Try → |
| Ends with | .*suffix$ | .*_sale_2026$ on spring_sale_2026 | Try → |
The negative side works the same way: does not match regex is also full match, so ^/admin under it excludes the exact value /admin and keeps /admin/users - the verdict table for that trap is on the exclude page path guide, and because RE2 rejects lookahead you build exclusions with that operator or an inverted alternation, never (?!...) (RE2 vs PCRE).
4. Copy-paste recipes
Every pattern below is RE2-safe (no lookahead, no backreferences), written for full match, and loadable into the tester via its Try link. Pick the scope first (section 2), then the dimension the recipe names.
| Goal | Scope / dimension | Pattern | Try |
|---|---|---|---|
| All blog and product pages | session or user / page_location | ^/(blog|products)(/.*)?$ | Try → |
| AI referrers (exact hosts) | user / source | ^(chatgpt\.com|perplexity\.ai|gemini\.google\.com|claude\.ai|copilot\.microsoft\.com)$ | Try → |
| AI referrers (loose, catches sub-brands) | user / source | .*(chatgpt|perplexity|claude|gemini).* | Try → |
| Campaign set | session / campaign | ^(spring|summer|winter)_sale_2026$ | Try → |
| Pages carrying a campaign tag | event / page_location | .*[?&]utm_source=(newsletter|partner)([&].*)?$ | Try → |
| Checkout funnel steps | event / event_name | ^(begin_checkout|add_to_cart|add_payment_info|purchase)$ | Try → |
Exact-host beats loose matching when you care about chatgpt.com.br not counting as AI traffic - the loose pattern intentionally trades that precision for sub-brand coverage. Campaign names are case sensitive here: Spring_Sale_2026 does not match ^(spring|...)$.
5. Audience-only semantics: why an audience is not a segment
Once your pattern is right, the audience side adds rules a segment does not have. All figures below are from Google's audience documentation.
- Entry conditions & scope. An audience is created with include condition groups (AND across groups), optional sequences, and exclude groups evaluated after includes. The condition scope is the same trio - across all sessions, within the same session, within the same event - and each audience condition is capped at 500 characters.
- Static vs dynamic evaluation. By default membership is dynamic: users are added when they meet the conditions and removed when they stop meeting them. The "at any point" option makes it static - once true, always a member for the evaluation window.
- Membership duration. Max 540 days from the last time the user qualified. With "reset on new activity" enabled the duration is limited to 14 months; each qualifying visit resets the clock to the full value.
- Refresh lag. A new audience takes 24-48 hours to accumulate users, and it is not retroactive - it starts from the save date (Google Ads audiences additionally get up to 30 days of backfilled data). Expect different counts than the equivalent segment; Google says that is intentional.
- Audience trigger. Fire an event when a user becomes a member - up to 20 trigger events per property, with an optional additional event (up to one per day) when membership refreshes. Metadata from the qualifying event is copied (session info, timestamp - not the page). Trigger events cannot themselves be used as audience conditions.
- Limits. 100 audiences per property (400 on 360), 10 conditions per audience, and members re-evaluate on every visit.
In short: build a segment to answer "what does the data look like for these rows, retroactively"; build an audience to create a living list you activate in Google Ads or trigger events on. Same regex, different machine.
6. Gotchas
- No lookahead. GA4 runs RE2:
(?!...)and(?=...)are rejected outright. Exclusions go through does not match regex or an inverted alternation - details and the legal moves are on the exclude page path guide and RE2 vs PCRE. - Case sensitivity. Full regex is case sensitive by default.
^purchase$does not catchPurchase; normalize in your event naming (see event filter regex) rather than trying inline flags, which are not a documented feature of the condition builder. .*greed eats the query string. Onpage_locationthe trailing.*happily spans?utm_source=..., so an "ends with" anchor after it is meaningless - and a pattern like^/checkout.*matches the whole URL, query included. Prefer the path dimension when you mean paths, or terminate with an explicit([?&].*)?$(recipe 5 above). Try →- Conditions vs filters inside one segment. Inclusion groups run first, exclusions second; groups are AND-ed while conditions inside a group can combine AND or OR; sequences impose order and can carry their own time constraint. Adding "contains blog" and "contains checkout" as two conditions in one group is an AND that can never fire (one page path is rarely both) - use OR inside the group, or two groups.
- Counts differ between segment and audience. Not a bug: retroactive query-time filter vs evolving membership list (section 1). If you reconcile numbers, decide which feature owns the definition first.
FAQ
Is segment regex in GA4 full match or partial match?
Full match. Google's regex doc: GA is full regex and case sensitive by default, and partial matching requires metacharacters - wrap your pattern in .* on both sides. The segment/audience condition builder offers matches regex / does not match regex only; there is no partial option to select (standard report filters and channel groups are the surfaces that have one - see match types).
Same regex - why do my segment and audience return different user counts?
They are different features. A segment is a retroactive query-time filter with no membership logic; an audience is a membership list built from the save date, with members entering and leaving as conditions are met or missed. Google documents the differing counts as intentional.
Can I exclude users with regex in a segment?
Yes. Inclusion condition groups are evaluated first, exclusions after. Build the negative with does not match regex (full match, so anchor deliberately) or an inverted alternation under matches regex. RE2 has no negative lookahead, so (?!...) is rejected - worked examples here.
Why did my new audience show zero users after I saved it?
Audiences take 24-48 hours to accumulate after creation and are not calculated retroactively from before the save date. Members then appear as users meet the conditions on later visits (Google Ads audiences additionally receive up to 30 days of backfill).
Can I fire a conversion when someone enters my audience?
Yes - that is an audience trigger: up to 20 trigger events per property, with an optional additional event (up to one per day) when membership refreshes. The qualifying event's metadata (session, timestamp) is copied to the trigger event, but the page is not, and trigger events cannot be used as conditions for another audience.
Related on RegexLab: GA4 regex match types (which surface offers which operator), GA4 exclude page path regex (negative patterns without lookahead), GA4 page path regex, GA4 event filter regex, Unassigned traffic regex (channel group contrast), RE2 vs PCRE and the pattern library.