Regular expressions is a language that every analyst needs to know when working with web analytics tools (and a lot of others aswell). Regular Expressions (or RegEx) allows you to filter, create segments, group together values and more.
The scary thing is that well it appears to be code like and this isn’t every analysts best skill-set. The truth is that it isn’t as hard as all that. Any coder of any level will tell you that you need to make sure that your coding is accurate. The computer can’t be expected to make a judgement call based on a close spelling. It needs to be accurate.
So in the lives of analysts. When writing Regular Expressions just be sure to give it the love and attention that you give your stakeholder reports. Imagine the storm of trouble inaccurate reports would bring down on you. Regular Expressions – well if they aren’t written accurately then they simply won’t work (or work as expected).
Sample – filtering on a domain name
this will select everything that has orange.co.uk in the string. So imagine you’re looking at a long list of email addresses and you’re wanting only those that are from orange.co.uk. Then simply apply the above.
Most Common Used RegEx
|^||Denotes the beginning of a string|
|\||Ignore the next character|
|(0-9)||Any value between 0 and 9|
||||Or e.g. a|b will give a or b|
|$||Denotes the end of a string|
- 123.orange.co.uk – matching
- 456.orange.co.uk – matching
- hub.orange.co.uk – not matching
How to Test RegEx
There are plenty of testers that you can plugin in both your proposed RegEx and also a test string. If it matches then it will highlight. Similarly if it only part matches then you will only see a part highlight.
The one I’ve used most over the past few months is: Regexr.com. I find their interface very friendly and easy to use. However, just because it works in a tester doesn’t necessarily mean that it is going to work in Google Analytics or another analysis package. Some of these analytics providers have a custom RegEx implementation so it is always good to check.
You can see here that the I’ve highlighted the test string and it’s highlighted in blue by RegExr.com indicating that the value matches the regular expression.
All you need to do is them simply copy the string and place where required.