Guide 108 · Container · GA4 + Tag Manager
Create a regex table variable: match a pattern, not a list of exact values
A lookup table matches exact values, which breaks down when the values follow a pattern — /page1.html through /page9.html, for example. A regex table is the same idea with regular expressions: each row is a pattern, and the first pattern that matches returns its output. Google's own worked example uses three patterns to sort nine pages into three groups: .*/page[1-3]\.html.* returns foo, .*/page[4-6]\.html.* returns bar, .*/page[7-9]\.html.* returns baz. This guide builds that table and checks all nine pages against it.
After step 4, Preview mode shows the variable returning foo for the first three page addresses, bar for the next three, and baz for the last one — 9 addresses sorted by 3 patterns.
Download the container fragment: the regex table fragment (JSON) (export format version 2, 2020 bytes, MD5 7ee5d2b619962332d014e54b549d3cb9). It holds the Regex - Page Group variable with Google's three example patterns, and a GA4 event tag that reads it on page-view. The file is a hand-built import template, validated structurally — it was not exported from a live container.
What you need
- An input variable whose values follow a pattern. The worked example uses the Page URL, which Google's own example uses as the regex table input.
- The patterns written out before you build. Three patterns in the worked example, each one covering a set of pages. A pattern you have not tested is a guess — check it against a real address first.
- Edit access to the container. Creating a variable is a container edit.
The trace
- Go to Variables and click New under User-Defined Variables. The Variables page has two sections; user-defined variables are the lower one.
- Click Variable Configuration and choose RegEx Table. RegEx Table is listed under Utilities. Pick it and the configuration shows an input selector and an empty two-column table: Pattern on the left, Output on the right.
- Set the input to Page URL. Click the input selector and choose the Page URL built-in variable. The table will test the current page's URL against each pattern in order.
- Add Google's three example patterns. Row one: pattern
.*/page[1-3]\.html.*returnsfoo. Row two:.*/page[4-6]\.html.*returnsbar. Row three:.*/page[7-9]\.html.*returnsbaz. The worked check covers 9 addresses:page1, the wwwpage1variant andpage2with a fragment return foo — 3 of them;page5, thepage5address with a query string andpage6return bar — 3 more;page9returns baz. That is 3 + 3 + 1 = 7 addresses checked in Google's own table, all three patterns used. - Set a default value and name the variable. Click Set Default Value and enter a value for when no pattern matches — without one, the variable returns nothing on every other page. Name it
Regex - Page Groupand click Save. By default, patterns must match the full input string and are case insensitive; the Advanced Settings can change both.
Dead ends
DEAD END — A PATTERN THAT MATCHES TOO MUCH. Patterns run from the top of the list to the bottom and the first match wins. A loose pattern at the top — .*page.* — matches every page and the rows below it never run. Write the most specific pattern first, or the broad one last.
DEAD END — FULL MATCHES ONLY, LEFT ON BY ACCIDENT. By default a pattern must match the full input string. A pattern written to match a fragment of the address — page1 on its own — matches nothing until Full Matches Only is switched off in Advanced Settings, which lets a pattern match anywhere in the input.
DEAD END — CAPTURE GROUPS WITHOUT THE REPLACE SETTING. A pattern with a capture group such as /(news)/page(2)\.html can return parts of the match with $1 and $2 — but only when Capture Groups and Replace Functionality is enabled in Advanced Settings. Without it, the group is just part of the pattern.
End state
One variable, Regex - Page Group, sorting nine pages into three groups with three patterns. A tenth page that follows the same numbering needs no new row — it falls into its group by pattern.
Sources
- Tag Manager Help — User-defined variable types for web — RegEx Table variable type, the three example patterns and their foo, bar and baz outputs, the seven matched example addresses, top-to-bottom matching, Set Default Value, Full Matches Only and Ignore Case in Advanced Settings
Checked 11 November 2026. The click paths above are the ones in Google's help pages, opened 11 November 2026. No step in this guide was run inside a live Analytics property or a live Tag Manager container, because both need a Google sign-in and this site does not sign in as anyone. The container file was validated structurally instead: export format version 2, every tag's firing trigger resolves, every variable the tags reference exists in the file, and the tag types are the documented ones. Google moves menu items without warning; if a path on this page no longer matches, the linked help page is the current map. The container fragment for this guide is 2020 bytes (1.97 KB, 0.99% of the reported 200 KB container size limit), MD5 7ee5d2b619962332d014e54b549d3cb9, and passed 15 structural checks.