Lesson 11 of 15
RegEx Table Variable
① Connect your GTM container
Paste your container ID to load it into this page. It only ever runs here.
Advanced: use a specific environment
A Lookup Table needs an exact match for every value. But paths come in endless variations, /blog/post-1, /blog/post-2, /product/headphones, and you cannot list them all. A RegEx Table matches each input against a pattern instead of a literal, so one row can catch a whole family of URLs.
Rows are tested top to bottom and the first match wins, so order matters. A broad .* pattern matches everything, which is why it belongs last as a catch-all, otherwise it would swallow every path before the specific rows get a turn.
Goal
Build a RegEx Table on Page Path that buckets URLs into sections, with a catch-all last.
Build it in GTM
Create the RegEx Table variable
Go to Variables → New and choose RegEx Table. Set Input Variable to{{Page Path}}.Turn on full matches only
Open Advanced Settings and tick Full matches only. This anchors each pattern so^/(cart|checkout)$matches the whole path and does not partially match longer URLs.Add the specific patterns first
Add rows in this order:^/blog/.*tocontent,^/product/.*toproduct, then^/(cart|checkout)$topurchase. Each left cell is the pattern, each right cell the output.Add the catch-all last
As the final row add.*tootherso anything unmatched still gets a value. Name itRT - page sectionand Save.
Debug in Tag Assistant
Copy this lesson's live URL and paste it into GTM Preview, that is the page Tag Assistant connects to. It has the clickable elements, so this page stays clean for reading.
- In your GTM, click Preview.
- Paste the live URL above and click Connect.
- Interact with the live page and watch your tag fire in Tag Assistant.
What you should expect to see
{{RT - page section}} resolves to content on /blog/post-1, product on /product/headphones, purchase on /cart, and other on anything else.Verify your container
Built it? Export your container, Admin → Export Container, choose your workspace, then drop the JSON here to check it against this lesson.
Drop your container .json here
or browse · checked in your browser, nothing is uploaded