The caret is the character I start many of my regular expressions filters with. It will most likely be right at the beginning of yours too! It’s your way to tell Google Analytics that you only want to match with strings that start with the following RegEx.
If you’re filtering for a precise value, it’s easy and efficient to always use the caret. You can be sure that you wont pick up anything nasty or unexpected in your results.
Caret: examples of use
One example of using a caret would be when filtering your referrers report.
Say you want to look at traffic just from a referer’s main site ‘referrer.com’, but not from their mobile site ‘m.referrer.com’ or their blog, ‘blog.referrer.com’.
Just filtering on ‘referrer.com’ will return all three of the above.
the RegEx you should use is ‘^referrer.com’.
Another common problem caused by not using the caret is where people have a large site with many pages with similar names.
For example, in a content report, I might want to filter for my ‘/web-analytics/’ category.
I may have a post that has the URI ‘/ab-testing/web-analytics-tools-for-mvt’. I don’t want this included in my results.
The caret is born for this situation. If you know what you want your results to start with, always use a caret!
If I search for ‘web-analytics’ I would return all of the above.
The Regular Expression for the above example would be ‘^/web-analytics/’
How not to use the caret
The caret must match the very beginning of a string as it would appear in one of your reports in Google Analytics. A very common mistake is for people to think only about what they’re trying to match, rather than the whole string as it exists in the reports.
For example, I might want to match everything in my subfolder ‘google-analytics’. A typical string on my site is ‘/web-analytics/google-analytics/page-name’
If I use ‘^google-analytics’ I will get zero results. Firstly because all the values in my content report begin with a forward slash ‘/’. But also because I’ve made the mistake of trying to put a caret halfway through the values I’m filtering. It will only match with the beginning. So the correct RegEx for this example is ‘^/web-analytics/google-analytics/’
I would love to hear about your experiences of using RegEx, particularly if I’ve been in any way helpful? Please let me know any thoughts you have in the comments below…
Links to the rest of the series:
RegEx 1: Introduction
RegEx 2: Pipe
RegEx 3: Brackets
RegEx 4: Question Mark
RegEx 5: Backslash
RegEx 6: Plus Sign
RegEx 7: Dot
RegEx 8: Star
RegEx 9: Dot Star
RegEx 10: Caret – You are here!
RegEx 11: Dollar Sign
RegEx 12: Square Brackets
RegEx 13: 5 Great Places to use RegEx