<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Count Of Tuscany</title>
    <description>The latest articles on DEV Community by Count Of Tuscany (@countoftuscany).</description>
    <link>https://dev.to/countoftuscany</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4190470%2Fee77b848-1559-4da2-a9be-4127a60384f2.png</url>
      <title>DEV Community: Count Of Tuscany</title>
      <link>https://dev.to/countoftuscany</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/countoftuscany"/>
    <language>en</language>
    <item>
      <title>Your Regex Works in JS but Fails in GA4? Full-Match, RE2, and the Patterns That Actually Work</title>
      <dc:creator>Count Of Tuscany</dc:creator>
      <pubDate>Wed, 28 Oct 2026 14:21:57 +0000</pubDate>
      <link>https://dev.to/countoftuscany/your-regex-works-in-js-but-fails-in-ga4-full-match-re2-and-the-patterns-that-actually-work-dm</link>
      <guid>https://dev.to/countoftuscany/your-regex-works-in-js-but-fails-in-ga4-full-match-re2-and-the-patterns-that-actually-work-dm</guid>
      <description>&lt;p&gt;You build a regex, test it in your editor, it works. You paste it into a GA4 segment or comparison and... zero rows. No error, no warning, just silence.&lt;/p&gt;

&lt;p&gt;Two features of GA4 explain almost every one of these failures.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. GA4 matches the &lt;em&gt;whole&lt;/em&gt; value, not a substring
&lt;/h2&gt;

&lt;p&gt;In JavaScript, &lt;code&gt;/blog/&lt;/code&gt; matches &lt;code&gt;"/blog/my-post"&lt;/code&gt; happily. In GA4, filters use &lt;strong&gt;full-match semantics&lt;/strong&gt;: &lt;code&gt;/blog/&lt;/code&gt; matches the value &lt;code&gt;/blog&lt;/code&gt; and nothing else.&lt;/p&gt;

&lt;p&gt;That's why every GA4 pattern you find in the wild is wrapped in &lt;code&gt;.*&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# matches any page path containing /blog/
.*/blog/.*
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two flavors to remember:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;"is one of my regex patterns"&lt;/strong&gt; (segment dimensions): full match, wrap with &lt;code&gt;.*&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;"partially matches regex"&lt;/strong&gt; (some comparison surfaces): substring match, no wrapping needed&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Test the exact flavor you'll use - mixing them up is the number one source of "my regex works in the preview but not in the report".&lt;/p&gt;

&lt;h2&gt;
  
  
  2. GA4 runs RE2, not JavaScript's RegExp
&lt;/h2&gt;

&lt;p&gt;GA4 (like BigQuery, Go, and Rust) uses Google's &lt;strong&gt;RE2&lt;/strong&gt; engine. RE2 is linear-time - it can never blow up on adversarial input - but that guarantee costs it three PCRE families:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;No lookahead / lookbehind&lt;/strong&gt;: &lt;code&gt;foo(?=bar)&lt;/code&gt;, &lt;code&gt;(?&amp;lt;=/)(\w+)&lt;/code&gt; - rejected&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No backreferences&lt;/strong&gt;: &lt;code&gt;(foo|bar)\1&lt;/code&gt; - rejected&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No atomic groups / possessive quantifiers / recursion&lt;/strong&gt; - rejected&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The RE2-friendly mindset:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Instead of&lt;/th&gt;
&lt;th&gt;Write&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;foo(?=bar)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;(foo)bar&lt;/code&gt; - capture the part you need&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;negative lookahead &lt;code&gt;(?!&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;a negated class &lt;code&gt;[^x]&lt;/code&gt;, or an exclude filter&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;`(foo&lt;/td&gt;
&lt;td&gt;bar)\1`&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;non-greedy tricks&lt;/td&gt;
&lt;td&gt;plain &lt;code&gt;.*&lt;/code&gt; - GA4 matches the full value anyway&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Three patterns that actually work in GA4
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Page path filter - all blog posts:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.*/blog/.*
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Event name filter - the ecommerce funnel:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(view_item|add_to_cart|begin_checkout|add_payment_info|purchase)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Custom channel grouping - organic social:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.*(facebook|instagram|linkedin|twitter|x\.com|t\.co|youtube).*
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(Notice the escaped dot in &lt;code&gt;x\.com&lt;/code&gt; - unescaped, it would also match &lt;code&gt;xXcom&lt;/code&gt;.)&lt;/p&gt;

&lt;h2&gt;
  
  
  The workflow that stops the guessing
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Write the pattern in a tester that lets you paste your &lt;strong&gt;real values&lt;/strong&gt; (the actual &lt;code&gt;page_path&lt;/code&gt; rows, the actual event names - not your memory of them).&lt;/li&gt;
&lt;li&gt;Check which engine it targets. JavaScript-valid is not RE2-valid; if your pattern contains &lt;code&gt;(?=&lt;/code&gt;, &lt;code&gt;(?!&lt;/code&gt; or &lt;code&gt;\1&lt;/code&gt;, it will never run in GA4.&lt;/li&gt;
&lt;li&gt;Only then paste it into GA4.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I kept failing at step 2 myself, so I built &lt;a href="https://regextester.site/" rel="noopener noreferrer"&gt;RegexLab&lt;/a&gt; - a free, browser-only tester that shows match/no-match per line and keeps the RE2 gotchas visible. There's also a &lt;a href="https://regextester.site/regex-patterns/" rel="noopener noreferrer"&gt;pattern library&lt;/a&gt; with tested, copy-paste patterns (dates, URLs, UTM parameters, log levels), each with an RE2-compatibility note, and a dedicated &lt;a href="https://regextester.site/re2-vs-pcre/" rel="noopener noreferrer"&gt;RE2 vs PCRE page&lt;/a&gt; listing every unsupported construct with its replacement.&lt;/p&gt;

&lt;p&gt;Nothing leaves your browser - the whole thing is client-side JavaScript RegExp under the hood.&lt;/p&gt;

&lt;h2&gt;
  
  
  TL;DR
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;GA4 = full match. Wrap substring patterns in &lt;code&gt;.*&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;GA4 = RE2. No lookahead, no backreferences, no lookbehind&lt;/li&gt;
&lt;li&gt;Test against your real data, with the right engine in mind, before you ship the pattern&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;What's the regex problem that cost you the most debugging time? Mine was a lookahead that silently matched everything in preview and nothing in production.&lt;/p&gt;

</description>
      <category>regex</category>
      <category>regexga4</category>
      <category>regextester</category>
      <category>opensource</category>
    </item>
    <item>
      <title>Why Your GA4 Regex Keeps Failing — 2 Rules That Fix 99% of It</title>
      <dc:creator>Count Of Tuscany</dc:creator>
      <pubDate>Sat, 17 Oct 2026 12:28:22 +0000</pubDate>
      <link>https://dev.to/countoftuscany/why-your-ga4-regex-keeps-failing-2-rules-that-fix-99-of-it-33f8</link>
      <guid>https://dev.to/countoftuscany/why-your-ga4-regex-keeps-failing-2-rules-that-fix-99-of-it-33f8</guid>
      <description>&lt;p&gt;If you ever pasted a regex into Google Analytics 4 and got zero rows back&lt;br&gt;
while the exact same pattern works fine in your editor — you didn't write a&lt;br&gt;
"wrong" regex. You wrote one that GA4 doesn't run the same way.&lt;/p&gt;

&lt;p&gt;Two differences explain almost every failure.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. GA4 matches the &lt;em&gt;whole&lt;/em&gt; string
&lt;/h2&gt;

&lt;p&gt;GA4's regex condition is a &lt;strong&gt;full match&lt;/strong&gt;, not a "contains".&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/blog/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;In most regex engines, this finds &lt;code&gt;/blog&lt;/code&gt; inside &lt;code&gt;/blog/ga4-guide&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;In GA4, it matches only the exact string &lt;code&gt;/blog&lt;/code&gt;. &lt;code&gt;/blog/ga4-guide&lt;/code&gt; → zero rows.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Fix — wrap it:&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/blog/.*      → everything under /blog/&lt;br&gt;
.&lt;em&gt;blog.&lt;/em&gt;      → any path containing "blog"&lt;br&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
&lt;br&gt;
  &lt;br&gt;
  

&lt;ol&gt;
&lt;li&gt;GA4 uses RE2 — no lookahead, no backreferences
&lt;/li&gt;
&lt;/ol&gt;
&lt;/h2&gt;


&lt;p&gt;GA4 runs Google's RE2 engine: fast and safe, but it does &lt;strong&gt;not&lt;/strong&gt; support:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;lookahead &lt;code&gt;(?=…)&lt;/code&gt; / &lt;code&gt;(?!…)&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;lookbehind &lt;code&gt;(?&amp;lt;=…)&lt;/code&gt; / &lt;code&gt;(?&amp;lt;!…)&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;backreferences &lt;code&gt;\1&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A pattern like &lt;code&gt;ga4(?=-tips)&lt;/code&gt; fails silently. And because RE2 can't assert,&lt;br&gt;
"match X but not Y" logic is better expressed as two filters in GA4 itself&lt;br&gt;
(one include, one exclude) instead of one clever regex.&lt;/p&gt;

&lt;h2&gt;
  
  
  Patterns that actually work in GA4
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;You want&lt;/th&gt;
&lt;th&gt;Regex&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Pages under /blog/&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/blog/.*&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Product detail &lt;code&gt;/products/&amp;lt;slug&amp;gt;&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/products/[^/]+&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Event ending in &lt;code&gt;_click&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;&lt;code&gt;.*_click&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Source is google or bing&lt;/td&gt;
&lt;td&gt;`(google&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;URLs with a query string&lt;/td&gt;
&lt;td&gt;{% raw %}&lt;code&gt;.*\?.*&lt;/code&gt; (use &lt;code&gt;page_location&lt;/code&gt;, not &lt;code&gt;page_path&lt;/code&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Test before you paste
&lt;/h2&gt;

&lt;p&gt;Every pattern above can be checked live against sample data in a free,&lt;br&gt;
browser-only tester — no login, and no data ever leaves your device:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Tester:&lt;/strong&gt; &lt;a href="https://regextester.site/" rel="noopener noreferrer"&gt;https://regextester.site/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cheat sheet, 25+ ready-made GA4 patterns:&lt;/strong&gt;
&lt;a href="https://regextester.site/ga4-regex-cheatsheet/" rel="noopener noreferrer"&gt;https://regextester.site/ga4-regex-cheatsheet/&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Both run entirely client-side, so what matches in the tester matches in GA4.&lt;/p&gt;

</description>
      <category>regex</category>
      <category>regextester</category>
      <category>tutorial</category>
      <category>opensource</category>
    </item>
  </channel>
</rss>
