Advertisement

GTM Regex Trigger - Matches RegEx, Variables & Tested Patterns

Google Tag Manager triggers fire tags on events. To fire a tag only on certain pages or events, you add a trigger filter with the matches RegEx operator. This page covers the regex side of that filter: GTM's partial-match semantics (the opposite of GA4's full match), which variable decides anchoring, operator choice, and copy-paste recipes tested in your browser before you publish the container.

TL;DR: GTM trigger regex is partial match (substring) — Google's own example, \`/pro/\` matches products, promotions, professionals. Use Page Path for path-only rules (anchored at the first slash, no query string), Page URL when you need the query string, Page Hostname for subdomain splits. Prefer the matches RegEx (ignore case) operator for user-facing paths; use matches RegEx when case is meaningful. One regex trigger beats many triggers when the alternatives share a firing rule; a Lookup table wins when the same tag fires everywhere but a variable value changes per page. Test every pattern in the tester before publishing.

1. Where regex lives in GTM

Triggers default to firing on all events of their type. Add a trigger filter ("This trigger fires on → Some …") and each filter is a Variable / Operator / Value triple. Regex is available wherever trigger filters are used, via two operators: matches RegEx and matches RegEx (ignore case). CSS selectors are the other regex-adjacent operator, used on Click Element variables.

Trigger typeRegex operator?Typical use
Page ViewyesFire on a set of paths or hosts
Click (All Elements / Just Links)yesFire on link URLs or clicked-element classes
Custom EventyesFire on event-name patterns (see gotcha below)
Form SubmissionyesFire on form-action URLs
Scroll Depth, Timer, History Change, Element VisibilityyesFilter by URL or element

2. The variable decides the anchoring

The same pattern gives three different results depending on the variable. This is the single biggest source of "why didn't my trigger fire" tickets.

VariableWhat it holdsAnchoring effectUse when
Page PathPath only, starts at first /No query string; ^/blog/ is cleanSection/path rules (most common)
Page URLFull URL including query stringQuery params can break anchors; ^https?:// neededYou need UTM/campaign params
Page HostnameHost only (no path)Pattern must match host; no leading slashSubdomain splits (blog.example.com)

Google's regex doc confirms the partial-match semantics: the pattern /pro/ matches products, promotions, professionals and processes. If you need an exact value, anchor it yourself with ^ and $.

3. One regex trigger vs many triggers vs Lookup table

4. Copy-paste recipes

GoalVariablePattern (matches RegEx)Try
Fire on blog or docs pathsPage Path^/(blog|docs)/tester →
Fire on landing pagesPage Path^/(lp|landing)/tester →
Exclude admin / preview / stagingPage Path^(?!.*(admin|preview|staging)) (no lookahead in GTM → use negated alternation: ^/(?!admin|preview|staging) is illegal; use a separate "does not match" filter or list the allowed prefixes)tester →
Fire on a subdomainPage Hostname^blog\.example\.com$tester →
Fire on a query parameterPage URL[?&]utm_campaign=launchtester →
Fire on download / link clicksClick URL\.(pdf|zip|docx)$tester →
Fire on custom event namesEvent Name^(purchase|begin_checkout|add_to_cart)$tester →

GTM is partial match, so every "starts with" rule needs an explicit ^. Without it, /blog/ also matches /not-blog/here.

5. Gotchas

Test the trigger pattern before you publish the container
Load a pattern with a real variable value; the tester shows the exact match/no-match decision.
Open the regex tester →

FAQ

Is GTM trigger regex full match or partial match?

Partial match (contains). Google's own example: /pro/ matches products, promotions, professionals and processes. This is the opposite of GA4, which is full match — do not copy GA4 patterns into GTM triggers without re-anchoring.

matches RegEx vs matches RegEx (ignore case) - which one?

Use ignore case for user-facing paths and campaign parameters where casing varies; use the case-sensitive operator when case is meaningful. GTM has no documented inline (?i) flag position, so pick the operator instead.

Page URL vs Page Path vs Page Hostname?

Page Path is path only (cleanest anchoring, no query string). Page URL is the full URL (needed for UTM/campaign params). Page Hostname is the host only (subdomain splits). The same pattern gives different results on each.

One regex trigger vs many triggers vs Lookup table?

One regex trigger wins when alternatives share a firing rule. Many triggers win when different tags fire for different groups. A Lookup table wins when the same tag fires everywhere but a variable value changes per page.

Why does .* match everything on a custom event trigger?

Google's trigger docs note that a .* pattern on a custom event name matches every event. That is by design for catch-all rules, not a bug - scope it with a real prefix or event-name list before publishing.

Related on RegexLab: GA4 regex match types (full vs partial per surface), GA4 page path regex, Looker Studio regex, Search Console regex, RE2 vs PCRE and the pattern library.