/sir-albert:ga4-regexfrom Sir Albert
Validate, test, and explain regex patterns for Google Analytics 4 (GA4) and Google Tag Manager (GTM). Use whenever someone writes, debugs, or asks about a GA4 regex — including audiences, explorations, custom definitions, data stream filters, internal/cross-domain referral exclusions, unwanted referrals, GTM trigger filters, or Looker Studio regex matches. Trigger on phrases like "GA4 regex", "regex for page_path", "match these URLs", "exclude this campaign", "regex tester", "RE2", "why doesn't my regex match in GA4", or any combination of GA4/GTM + regex/pattern/match/exclude/filter. Especially trigger when the user shares a regex that uses lookbehind, backreferences, or named groups — GA4 uses RE2, which silently rejects or fails on PCRE-only features, and surfacing that is the main point of this skill.
Ships in Sir Albert. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
Help marketing operations, analytics, and growth teams write regex patterns that actually work in GA4 and GTM — not just regex that works on regex101. The headline value of this skill is catching RE2 incompatibilities before they ship to production audiences, exclusion lists, or trigger conditions.
Most regex tutorials assume PCRE (Perl-Compatible Regular Expressions) — the flavor used by JavaScript, Python, regex101.com, and most online testers. GA4 and the Google Tag Manager server-side runtime do not use PCRE. They use Google's RE2 engine, which deliberately rejects features that allow catastrophic backtracking.
This means a pattern that tests perfectly on regex101.com can:
The job of this skill is to (a) explain GA4's regex flavor, (b) validate patterns against RE2 rules, and (c) provide a tested pattern library for the common GA4 jobs.
Use whenever:
Do not use this skill for:
re or JS RegExp directly)REGEXP for BigQuery exports — BigQuery uses RE2 too, but the GA4 export schema concerns are different (point user to BigQuery docs)When a user brings a GA4 regex question, walk through these steps in order. Skip steps that don't apply.
GA4 surfaces handle regex slightly differently. Ask or infer which one:
| Surface | Engine | Anchoring | Case |
|---|---|---|---|
| GA4 Audience builder (matches regex) | RE2 | Partial match by default (use ^...$ for full) | Case-sensitive unless using (?i) |
| GA4 Explorations filter (matches regex) | RE2 | Partial match | Case-sensitive |
| GA4 Data stream — unwanted referrals | RE2 | Domain match, partial | Case-insensitive |
| GA4 Data stream — internal traffic IPs | CIDR or RE2 | n/a | n/a |
| GA4 Cross-domain configuration | RE2 | Domain match, partial | Case-insensitive |
| GTM client-side trigger filter | JavaScript RegExp (PCRE-ish) | Partial match | Configurable per trigger |
| GTM server-side (sGTM) | RE2 | Partial match | Configurable |
Looker Studio REGEXP_MATCH | RE2 | Full match required | Case-sensitive |
Looker Studio REGEXP_CONTAINS | RE2 | Partial match | Case-sensitive |
Anchoring is the #1 source of bugs. GA4 audiences do partial matching — ^/products matches /products AND /products/123. Looker Studio's REGEXP_MATCH does full matching — ^/products matches nothing unless the entire string is /products.
Read references/re2-rules.md for the full incompatibility list. The high-impact ones to check every pattern for:
(?<=foo)bar or (?<!foo)bar → NOT SUPPORTED in RE2. Common in PCRE tutorials. Will silently fail in GA4.(\w+)\s+\1 (matching the same captured group again) → NOT SUPPORTED.a++, a*+, a?+ → NOT SUPPORTED.(?>foo) → NOT SUPPORTED.(?R) or (?0) → NOT SUPPORTED.Lookahead ((?=foo), (?!foo)) is supported in RE2 in recent versions but is NOT supported in GA4 specifically — GA4 uses RE2 in a mode that rejects lookahead. If a user has lookahead, rewrite without it.
If you spot any of the above, flag immediately. Don't try to "fix" the regex silently — show the user what's wrong, explain why, and offer a RE2-compatible rewrite.
If the user provided test strings, run the pattern against them using Python's re2 library (which mirrors GA4 behavior) or, if re2 isn't installed, use Python's built-in re with a warning that PCRE-specific features won't be flagged.
# Preferred: use scripts/test_regex.py which handles both engines
python /path/to/ga4-regex/scripts/test_regex.py --pattern "^/products/.*" --strings "/products/123" "/about"
The script outputs per-string match results, capture groups (if any), and RE2 compatibility warnings.
GA4 supports capture groups in specific places (e.g., extracting a value from page_location into a custom dimension via Google Tag Manager). When the user's pattern has (...), explicitly tell them which group captures what — users routinely miss that group 0 is the whole match and group 1 is the first parenthesized subexpression.
For common GA4 jobs, don't write a pattern from scratch — pull from references/patterns.md. Examples:
^/products/^/contact$[?&]utm_ (NOT ^utm_ — utm params don't start the URL)^brand[-_]campaign$^(staff|admin|internal)\.example\.com$If a user's hand-written pattern overlaps with a library pattern, suggest the library version with a note on why it's more robust.
Default to this structure for any regex response:
Pattern: <the regex>
Surface: <GA4 audience / Looker Studio / etc.>
RE2-compatible: yes / no (with reason)
Anchoring: full / partial / unanchored
Case-sensitivity: <as written>
Matches: <test results, if test strings provided>
Notes: <gotchas, suggested alternatives>
Keep it scannable. Marketing ops users want the verdict first, the explanation second.
Load these when relevant — do not paste their full contents into responses, summarize and link.
references/re2-rules.md — Full RE2 incompatibility list, with PCRE → RE2 rewrites for each blocked featurereferences/patterns.md — Tested pattern library organized by GA4 use case (page_path, UTM, event names, referrals, domains)references/surfaces.md — Per-surface behavior cheat sheet (where regex appears in GA4/GTM and how each one handles anchoring, case, and partial matching)scripts/test_regex.py — Test one or more patterns against one or more strings, with RE2 compatibility checking. Run before claiming a pattern works.references/re2-rules.md or run the test script — don't guess./products/.* thinking they need .* at the end → unnecessary in partial-match surfaces, harmful in full-match surfaces if anchored wrong^utm_source=brand$ for a page_location field → utm_source is never at the start of a URL, the anchor is wrongexample\.com for unwanted referral exclusion → matches notexample.com too; need ^example\.com$ or (^|\.)example\.com$(?<=...) lookbehind → won't work in GA4, needs rewriteWhat SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub gal-tab/sir_albert --plugin sir-albert42 skills in this plugin
/board-of-advisorsAssemble a virtual "Board of Advisors" offering 4 distinct perspectives on a problem, decision, or strategy. Use when the user asks for "board of advisors", "multiple perspectives", "evaluate this decision from different angles", or "4 points of view"./brainstormUse when exploring angles, sharpening thinking, attacking a plan, running a panel of advisors, drilling an idea with relentless questions, zooming out on context, designing a solution, or receiving a context dump asking for your opinion or a recommendation. Triggers on: "brainstorm this", "grill this", "attack this", "zoom out", "play devil's advocate", "let's design this", "board of advisors", "sharpen this", "stress test this", "find holes in this", "fresh perspective", "4 perspectives", "want to build X", "want to understand what's happening", "look at this and advise", "what's really going on here", "here's the situation"./buildOther plugins' skills for the same job