Advertisement

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".

FeatureWhat it isWhen it changes past dataLives where
SegmentA set of conditions that filters data in an exploration - no membership logic, fully retroactiveImmediately: it is a query-time filter, so any date range you query is filtered the same wayExplore only (10 per exploration, 50 saved per property)
AudienceA group of users who meet your conditions - users enter and exit over timeNever 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 groupA grouping rule applied when a report is computed (source/medium → channels)Yes: saved rules re-sort past sessions into the new groups immediatelyReports, 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:

# the user's activity day 1 s1: /blog/post-a, /pricing day 2 s2: /pricing, /checkout day 2 s3: /pricing, /about # the one regex, used at all three scopes ^/(blog|checkout)(/.*)?$
ScopeQuestion it answersWhat the regex seesRows back
EventWhich events happened on a blog or checkout page?Each event's own page_location alone2 events - /blog/post-a, /checkout
SessionWhich sessions touched a blog or checkout page?Every event inside a session where at least one event matched4 events - all of s1 + s2 (s3 never matched, so its /pricing and /about are out)
UserDid this person ever touch a blog or checkout page?All of the user's events, once any one of them matchedAll 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 wantWriteExample (full match)Try
Exact value^value$ (or plain value)San Francisco matches only San Francisco, not South San FranciscoTry →
"contains" behavior.*value.*.*San Francisco.* matches bothTry →
Starts with^prefix.*^/blog.* on /blog/post-aTry →
Ends with.*suffix$.*_sale_2026$ on spring_sale_2026Try →

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.

GoalScope / dimensionPatternTry
All blog and product pagessession 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 setsession / campaign^(spring|summer|winter)_sale_2026$Try →
Pages carrying a campaign tagevent / page_location.*[?&]utm_source=(newsletter|partner)([&].*)?$Try →
Checkout funnel stepsevent / 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.

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.

Test the pattern against real values before you save the condition
Full-match surprises show up instantly: load the recipe, swap in your own value, see the verdict.
Open the regex tester →

6. Gotchas

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.