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 type | Regex operator? | Typical use |
|---|---|---|
| Page View | yes | Fire on a set of paths or hosts |
| Click (All Elements / Just Links) | yes | Fire on link URLs or clicked-element classes |
| Custom Event | yes | Fire on event-name patterns (see gotcha below) |
| Form Submission | yes | Fire on form-action URLs |
| Scroll Depth, Timer, History Change, Element Visibility | yes | Filter 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.
| Variable | What it holds | Anchoring effect | Use when |
|---|---|---|---|
| Page Path | Path only, starts at first / | No query string; ^/blog/ is clean | Section/path rules (most common) |
| Page URL | Full URL including query string | Query params can break anchors; ^https?:// needed | You need UTM/campaign params |
| Page Hostname | Host only (no path) | Pattern must match host; no leading slash | Subdomain 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
- One regex trigger — alternatives share a firing rule and one tag fires for all of them. Use alternation:
^/(blog|docs|lp)/. - Many triggers — different tags fire for different groups, or the OR-condition is easier to read than one long alternation.
- Lookup table variable — the same tag fires everywhere but a variable value (content group, channel) changes per page. Regex lives in the table rows, not the trigger.
4. Copy-paste recipes
| Goal | Variable | Pattern (matches RegEx) | Try |
|---|---|---|---|
| Fire on blog or docs paths | Page Path | ^/(blog|docs)/ | tester → |
| Fire on landing pages | Page Path | ^/(lp|landing)/ | tester → |
| Exclude admin / preview / staging | Page 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 subdomain | Page Hostname | ^blog\.example\.com$ | tester → |
| Fire on a query parameter | Page URL | [?&]utm_campaign=launch | tester → |
| Fire on download / link clicks | Click URL | \.(pdf|zip|docx)$ | tester → |
| Fire on custom event names | Event 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
- Ignore case is an operator, not a flag. Pick "matches RegEx (ignore case)" instead of relying on
(?i)position. Google's docs do not document inline flags for GTM. .*on a custom event matches everything. Google's trigger docs flag this explicitly — scope it with a real prefix or an event-name list before publishing.- Regex vs CSS selector confusion. Click Element variables take CSS selectors, not regex. Use Click URL or Click Text for regex.
- Case sensitivity. GTM's default operator is case-sensitive; the ignore-case variant is a separate operator. GA4 is also case-sensitive; BigQuery is case-sensitive by default but has
(?i). - Test before publishing. GTM has no dry-run for trigger filters; a bad regex either never fires or fires on everything. Test the pattern + real variable value in the tester first.
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.