<?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>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>
