Upcoming LunaMetrics Seminars
Pittsburgh, Jan 12-16 Boston, Jan 12-16 New York City, Jan 26-30 Denver, Feb 9-13

Regular Expressions Part I: Escaping with a Backslash \





What are Google Analytics’ “Regular” Expressions?

This was the question that I asked in August 2006. Although this post is ostensibly from August, I am actually rewriting it in October. Now that I understand Regular Expressions for Google Analytics, I want to explain them in the easiest language possible (so I had to go back and rewrite.)

regular-expressions

The most basic expression is \ the backslash. Google Analytics ascribes this meaning to it:

\ escape any of the above

What they mean is, you can use a backslash to turn any special character into a not-so-special character. Google (and everyone else who talks about Regular Expressions) makes this hard by using the word “escape,” when they merely mean, use a backslash to take the magic out of a special character and make it an everyday character.

Although the backslash can be used with any special character, I see it used most often with a dot. This is because a dot is both a special character (see Part II), and one that is used with the Internet all the time (Example: www.myspace.com — we see it there twice.) On the Internet (and so, with Google Analytics) we almost always are using dots as regular dots and so need a backslash to keep it as a mere dot. Here’s an example: mysite\.com and here’s another one (this time, an IP address): 64\.68\.82\.164

Many thanks to my tutor in Australia, Steve. With his help, help from Justin Cutroni, and many hours of reading and rereading the Wikipedia page on Regular Expressions (I won’t even link there, it is so difficult), I learned Regular Expressions. Very late comment: This started as a mere question for me. This ended with a seventeen part series.

Backslashes \
Dots .
Carats ^
Dollars signs $
Question marks ?
Pipes |
Parentheses ()
Square brackets []and dashes -
Plus signs +
Stars *
Regular Expressions for Google Analytics: Now let’s Practice
Bad Greed
RegEx and Good Greed
{Braces}
Minimal Matching
Lookahead

Robbin Steif

Robbin Steif

About Robbin Steif

Our owner and CEO, Robbin Steif, started LunaMetrics ten years ago. She is a graduate of Harvard College and the Harvard Business School, and has served on the Board of Directors for the Digital Analytics Association. Robbin is a recent winner of a BusinessWomen First award, as well as a Diamond Award for business leadership.

http://www.lunametrics.com/blog/2006/08/13/regular-expressions-part-i-escaping-with-a-backslash/

6 Responses to “Regular Expressions Part I: Escaping with a Backslash \”

Anonymous says:

Good Afternoon!
a. Well that’s *one* way of giving positive feedback. :-)
b. “The next lesson…” Subtle. Really subtle. And publicly too. Now I have no excuse to wimp out. :-)

c. Switching into serious mode for a change: I think I understand what you’re asking with the third question. I suspect that that may actually be better answered next than the ^ & $ stuff. Mainly as we can attack another fundamental concept. Which in turn will act as a solid foundation for the rest.

Hmmmmm.

Cheers!
- Steve

Mark Stroup says:

I’ve not gotten much beyond ^ & $, so I’ll be interested in tracking your progress in learning regular expressions. Knock ‘em dead.

[…] expressies zeer gewenst. Uitgebreide informatie over reguliere expressies vind je onder andere op LunaMetrics. Wil je jouw reguliere expressies testen? Dat kan ook, dat kan hier en […]

[…] expressies zeer gewenst. Uitgebreide informatie over reguliere expressies vind je onder andere op LunaMetrics. Wil je jouw reguliere expressies testen? Dat kan ook, dat kan hier en […]

[…] Focus on the filters section and learn how to write a few basic regular expressions – there are more questions on this than I thought there would be […]

Jodi says:

If I have a website with a hyphen in its name, do I need to escape that hyphen with a backslash? For example, my-website.com … should it be my\-website\.com or my-website\.com ? I’m not using it in square brackets.