You’ve started delving into regex. You either (understand it)|(don\’t understand it), but chances are, if you were able to read that joke, you’re in the know. Congrats! Now that you know a little bit about regex and how it works, you’re probably wondering how you can apply it to Google Analytics, Google Tag Manager, Google Data Studio, and any other Google product you can get your hands on.
While your basic knowledge of regex will no doubt take you far, if you start to get more in depth into regex, you’ll need to know your limitations when it comes to Google products. I’ll start off with a background on regex, so easy a caveman could understand it! Then I’ll go into what kind of regular expression Google uses and whether or not you can use negative regular expressions in Google Analytics goals.
An Introduction to Regex Commonly Used Terms
A long, long time ago in a world very far away, I thought there was only one type of regex. Boy was I wrong. As I began reading more and more, I was running into words like regex flavors, regex engines, and regex syntax. After hours and hours of research, I think the best way to explain regex flavors, regex engines, and regex syntax is with pets.
Disclaimer: With the below metaphor, we’re going to have to assume that there are no outliers among dogs. That’s right, your dog who acts like a cat, your calm Jack Russell terrier, and your golden retriever who absolutely hates people all don’t count here.
I love dogs. There are many different breeds of dogs. I love regex. There are many different flavors of regex. Each breed of dog has a different look. Some have long hair that you have to groom constantly, others have short oily hair, some coats are all one color, while other coats are different colors.
Overall, dogs have four legs, a tail, paws, and similar body shapes. That’s not to say a Great Dane looks like a Maltese, but from far away you can tell they’re both dogs. Regular expressions, similarly, have different syntaxes. That is to say, some have long hair that you have to groom constantly…just kidding. In all seriousness though, although the regex can be arranged differently, you still can kind of tell from afar that it’s a regular expression.
In addition to looking different, different breeds have different characteristics. A Jack Russell Terrier has more energy than a bulldog, golden retrievers are known for being incredibly kid friendly, beagles howl something wonderful/terrible and still other breeds of dogs are known for being a little bit more particular about who they choose to get along with. Often when describing a breed, you’re also describing the way they act and look. When I mention that I have a chocolate lab, you understand that it is brown in color, approximately 60 – 70 lbs., and loves water. In the same way that breeds have characteristics, different regular expression flavors support different behaviors.
In the beginning we associated dog breeds with flavors of regex, but we didn’t get into the technical definition. The technical definition of a flavor is the syntax and behavior supported by a particular regex engine, where a regex engine is just the “machine” that processes the regex. Going back to our dog example, each breed is going to look a different way and have different characteristics.
Unfortunately for my extended metaphor, there’s no way to compare a regular expression engine to a dog. A regular expression engine is what actually processes your regular expression.
I’m going to finish my metaphor with a common-sense reminder. Some breeds don’t get along with other breeds. There’s a reason why there’s a big dog section and a small dog section in every dog park. Sure, some can live in harmony with each other (we’ve all seen that one little dog that just loves to play with big dogs), but others can’t. Similarly, different regular expressions are not always compatible with each other.
What kind of regular expression does Google Analytics use?
This is the kind of question that you don’t care about until you need to know the answer and can’t find any Google help document to guide you to it. Google’s regular expression engine of choice is RE2, sometimes referred to as ‘golang’ regex. If you’re using very simple regular expressions, this doesn’t matter. Here’s why it became a problem for me though: it doesn’t support negative regular expressions.
For example, if you’re setting up a destination goal and you want to capture any time someone submits a thank you form, EXCEPT for the help/support thank you form, you are sore out of luck. RE2 does not support negative regular expressions at the time of writing this article. So if you’re looking for the answer for “Can I exclude something with Regex in Google Analytics Goals?” The answer is no.
Summary
A regular expression engine is the actual processor of your regular expression. The syntax is how your regular expression looks and the flavor is a combination of the syntax and the different behaviors associated with a regular expression engine. Unfortunately, the flavor used by Google Analytics doesn’t support negative regular expressions, so you can’t use negative regular expressions in your Google Analytics goals.