Avoid Segment Definition Errors: Helpful Tool to Get Your Regex Right

Avoid Segment Definition Errors: Helpful Tool to Get Your Regex Right

The Good, The Bad, The UglyStandard analytics reports provide lots of data but usually scarce useful information that can be acted upon.  Standard reports typically lead to more questions. To get answers, and uncover useful insight to tackle the good, bad and ugly of your operations, you need to filter and segment, such as in the following situations:

  • A visitor locations report will tell you where visitors are located and how engaged they are, but you are probably not interested in the behaviour of people around the world.  Most likely you’re interested in a select few focused geographies where your best prospects or most loyal visitors are located.
  • A report showing all channels of traffic might be interesting, but you’re probably most interested in those channels that you have spent money driving traffic through, or can make changes to, thereby influencing future visitor behaviour.
  • In evaluating response to a new microsite, you want to exclude internal traffic because there’s been significant internal corporate promotion.

RegexIn some analytics tools, such as Google Analytics, the language of regular expressions, or “regex” are needed to restrict the data to be analyzed.  If you don’t use the right regex, your analysis will be incorrect.

There are many Regex testers but one of the simplest is regexpal.com.

At regexpal.com, paste the data you want to match in the area marked “1” and write your regex in “2”:

RegexPal.com

To demonstrate, let’s say we need to create a filter that will exclude internal traffic, and the IPs that are relevant are:

65.94.98.171
65.94.98.172
65.94.98.173
65.94.98.179
165.41.32.41
200.15.91.24

Paste the data above into regexpal.com:

RegexPal.comStart writing your regex.  As the expression is built, correct matches will show up in alternating blue and yellow rows:

RegexPal.comIf all your test data are rows of yellow and blue, your regex is correct and ready to use.

Here are the actions that Regex symbols drive:

Symbol or combo Action Example
. Match any single character str.pe matches stripe, strype, str1pe
* Match zero or more of the previous character bob*le matches boble, bobble, bobbbbble
? Match zero or one of the previous item bob?le matches boble, bobble but not bobbbbble
+ Match at least one of the previous item bob+le matches bobble, bobbbbble but not boble
| Means “or” blue|red matches either blue or red
^ Match to the start ^blue matches blue shoes but not navy blue shoes
$ Match to the end shoe$ matches blue shoe but not blue shoes or shoe sales
( )  Group into an item (thank you) means treat “thank you” as a grouped unit
 [ ]  Create a list to match to [1239] isn’t the number 1239 but a list of 1,2,3,9
 \ Make the character following literal, and not have any meaning \. means that the “.” is just a dot and not to be used for matching
.* Match anything blue.*shoes matches blue running shoes, blue striped shoes, as well as the phrase “blue isn’t a good colour for running shoes”

Give regexpal a try.  What do you think?  Do you have other favourite regextesters?

“The Good The Bad The Ugly” Image Credit: euchrideucrow.deviantart.com

By |2016-06-08T17:37:46-04:00January 9th, 2015|0 Comments

Leave A Comment