'Google Tag Manager - Regex match

I want to check if a specific string is included in a GTM variable. The value of this variable is a first-party-cookie value decoded via URI looking like this:

"\"prodirversion\":5,\"panellanguage\":\"de\",\"preferences\":false,"\"marketing\":true,\"necessary\":true,\"statistics\":false,\"social_"

I now want to check if the following string is included.

marketing":true

I created another variable with a regex table and tried different regex expressions but nothing seems to work. It works on online regex tester but not in Google Tag Manager.

My guess would be the following but it doesn't work.

marketing\\":true

or

marketing.{3}true 

or

marketing\\.{2}true

GTM variable



Solution 1:[1]

Some Regex engines will have an error on not escaping " char in marketing\\":true

Try escaping it like this: marketing\\\":true, and it should match.

Update:

  • marketing":true seems to be working in GTM
  • from that, we can conclude that escaping character \ in input string is for show only in GTM case, and should be ignored when regex testing/debugging.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1