The pipe “|” is the first thing most people learn in regular expressions. It’s the easiest rule to understand and is actually the one I use most often with the greatest results.
If you want to
filter your results for “Something”, and “Something else”, the pipe is the Regex to use.
Have a look at your ‘Top Content’ report. In the filter you have the choice of ‘contains’ or ‘does not contain’. It’s easy to filter for a directory or a page, but what if you want to have a look at two or more pages in a sub directory, or even in different ones?
I often have to look
at my colombian and spanish publications together, or I have tried some optimisation in some pages in a directory, but not others.
This is where you can use the pipe.
You have pages for green,
red, blue and yellow teeshirts, but you just want to report on the Red and Yellow ones. The URIs for these pages follow the convention: ‘/COLOUR/teeshirt.html’
In this instance you would put the following into your filter panel: red|yellow
To add blue you would enter: red|yellow|blue
TIP: Regex is hungry and will try to match everything it can within the rules you specify. For example, if you have a page called ‘blue’ and one called ‘royal-blue’ on your site the above regex will match both! The same is true if you have ‘/blue/mugs.html’ and ‘/blue/teeshirt.html’, or any other pages that match the simple criteria.
In the real world, I’m forever returning error pages, with parts of real urls in the reported error paths, in my reports erroneously. We will need more regex to deal with this issue! First of all lets make sure we’re down with pipes…
Give it a go with some real life examples on your own site, see if you can get false positives like the ‘royal blue’ above and make sure you understand what Google Analytics is doing with regex before moving on to have a look at brackets.
Links to the rest of the series:
RegEx 1: Introduction
RegEx 2: Pipe – You are here!
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
RegEx 11: Dollar Sign
RegEx 12: Square Brackets
RegEx 13: 5 Great Places to use RegEx