Regular Expressions for Google Analytics


For those of you just getting into online marketing and are experimenting with Google analytics, you may have come across the special characters known as regular expressions. Regular expressions are a set of characters that are used as a notation system to signify specific functions for matching strings of text with minimal effort. That may sound like a bit of a mouthful, but believe me it is not as complicated as it seems to begin with.

Many users are put off at first by these expressions; they can appear confusing, almost as if they are some kind of foreign language. You may  have stayed as far away as possible, or even have looked around, copying and pasting code from other sources when trying to create filters that require the use of these expressions. Yes, they can be intimidating at first, but they are surprisingly easy to understand once you get a handle on how and in what context they are supposed to be used. So now is your time to finally learn, believe me it will make things a lot easier in the long run and before you know it you will be using them with no problem at all!



The first set of characters I will be showing you are known as wildcards. A wildcard is basically an expression that can be substituted for any other standard character. Here are some of the most regularly used wildcard expressions:

Dot(.) –                The dot is used to match any one character; this can be a letter, number or special character. Meaning if you created the expression “.xample” it would match example, fxample, gxample etc, as well as 1xample and so on.

If you are hoping to match web addresses such as then you must use a backslash () before the dot. This stops the dot from being considered a wildcard. So your expression would look something like this

Asterisk(*) –       The asterisk is a very popular expression, it is used to match 0 or more of the previous character. So for instance if your company was using a 4 digit identification number for particular items, it could appear something like this ID0001. Creating a filter using the asterisk could look something like this ID0*1. This expression would return searches for ID0001, ID000001 as well as ID01 and even ID1, since the asterisk means 0 or more of the previous character in this case “0”.

The asterisk can also be used quite powerfully with the dot. As the dot is used as a substitute for any character and the asterisk is 0 or more of that character, using them together in the form (.*) means a search for a number of any character is possible.

Pipe (|) –              The pipe represents the logical expression “OR”. So for instance if you are looking at a report that contains ABCDE and you only wanted to view results for A and B you could create a filter using the expression A|B.

Question (?) –    Similar to the asterisk, the question mark matches 0 or 1 of the previous expression. So in the previous ID number example of ID0*1, if you replaced the expression with a question mark ID0?1, it would return searches for ID1, ID01 as well as all the other possible permutations using a single character. Unlike the asterisk however it won’t return results using greater than one character i.e. ID001.



Anchors unlike wildcards are not used to represent a character; they are instead used to control how terms are searched for. Two of the most commonly used anchors are explained here:

Caret (^) –           Simply if anything comes before the caret it is discounted. Using sub-domains as an example, if you had a website and two sub-domains, and but you only wanted to search only for strings that started with /example/ (the first option) then you could use the caret. Using the caret in an expression like this ^/example/ would discount the second option as /blog appears before it. The main domain is not listed in analytics as it is already known.

Dollar ($) –           The dollar sign is more or less the opposite to the Caret, it is used to signify the end of your string.  So for instance the expression “example$” would match terms like “this is an example” but not “example of how many…”

So there you have it, while this is not a comprehensive list of all the regular expressions for Google analytics available, it does cover some of those most commonly used and is more than enough to get started. Now go and try these expressions out for yourself. I am sure that over time you will get more and more used to them, and will definitely find them an increasingly useful timesaver that will help you to gain the information you need for your online marketing campaign faster than ever.