Go to Top

Testing Regular Expressions

Hello from the Pure Visibility newbie! After three full weeks on the job, I thought I’d venture out into blog land to introduce myself, and talk about TextWrangler, a tool that’s been a huge help as I learn more about testing regular expressions (or RegEx) in Google Analytics. Regular expressions are character patterns used to match text.

After some hands on experience using RegEx in Analytics, I could understand their usefulness, and wanted to make sure I was applying the expressions correctly. It can be tricky to test, because you may THINK you’ve correctly applied the result in GA if you’re seeing any results returned, but even if you see results, it’s possible that you’re not seeing the entire picture. Luckily, there is a great tool called TextWrangler, that makes it easy to test regular expressions, so you make sure you’re using the right expressions when searching in Analytics reports. TextWrangler is a free text editor available on Macs. TinyEdit has the same functionality needed for testing RegEx, and is available for Windows Users.

In my position as an analyst, I will mostly use RegEx in Google Analytics, to view groups of data based on sets of rules that I determine.  For example:

Many people arrive at the Pure Visibility site after looking for information about QR codes.  However, there are many variations of these terms: qr code, q r code, qr codes, qr-code, and so on.  To really understand how many people arrive at the site after searching on these terms, I need to use regular expressions in my Analytics reports.  But first, I want to make to make sure that I’m using the right regular expressions to bring up the appropriate results! So, I’ll test in TextWrangler using the following steps:

  1. First, enter several variations of the terms you want to have returned, as well as some terms you do NOT want to be returned.
  2. Next, hit Command/Apple + F to begin the process of returning results using RegEx.
  3. Make sure your cursor is at the top of the screen, as you will only see results for terms below your cursor (this has happened to me more than once!).
  4. Make sure you’ve selected ‘Grep’ under the matching option.  Select any other fields appropriate to your search.
  5. Use the appropriate regular expression/s in the ‘Find’ box.  In this case, I want to find any terms containing the letters Q and R in the same search term, so I’ll use parenthesis to group, and the pipe, to include an ‘or’ statement.  Using (qr|q r) means that I’ll find terms where Q and R appear directly next to each other OR with a space in between.
  6. Hit ‘Next’ or ‘Find All’ to see which results are returned.  Assuming you used the proper expression, you’re all set to plug into Analytics! If you didn’t get the results you expected, make sure your cursor was set to the top of the page, and review the article from the Google Analytics Help Center if needed.

Now, you’re ready for the real thing.  After logging into your Google Analytics account, select the appropriate report, and apply the RegEx in the search field.

Have fun and happy RegExing!

facebooktwittergoogle_plusredditpinterestlinkedinmailby feather
, , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>