Regular Expressions Part IV: The ending Anchor $
As regular readers know, I am learning about and sharing my lessons on Regular Expressions. In my last post on this topic, Part III, I wrote about the opening anchor, aka the carat symbol. It’s used at the beginning of some regular expressions. Today I am writing about its sister, this anchor $, which is sometimes used at the end of Regular Expressions (RegExen. I wish I had one of those “cool” smileys to easily insert here.)
In the Google Analytics very unhelpful Help section on Regular Expressions, it says this about the dollar sign:
$: match to the end of the field
What they really mean is, don’t match if the string from my website has any characters beyond where I have placed the dollar sign in my Regular Expression. The dollar sign signals all the characters that I want to match to. (This is the hard part about the explanation, it’s always hard to explain what the target is and what the RegEx is.)
So let’s say that you have some pages that end in htm and others in html. You want to write a Google Analytics Step 1 (part of a goal) for your email sign-up form, but you only want the new .htm version. Your RegEx might look like this:
The dollar sign tells the Google Analytics, if the page on your site has anything after the final “m” in “htm,” it doesn’t count as a match to this expression. Notice that I also used a backslash before the dot so that Google Analytics interprets it just as a dot, not as anything special.
I understood what it does pretty quickly, but I had to put this post off for at least a week in an effort to understand why anyone would ever use a dollar sign. Here’s the problem: if you have any campaign code whatsoever that gets attached to this string when someone lands on your site, there is no match. For example, let’s say someone lands on your site and when he looks up at the address bar, it says this:
As soon as there is campaign code, the dollar sign anchor will tell GA that there is no match. And it can be hard to remember everywhere that you would have campaign code and everywhere that you wouldn’t.
So forget the fanciful examples – why would anyone ever use it?
Once place you might use it would be with an IP address (for a filter, someone that you are trying to filter in or filter out.) You might have an IP addresss like this that you are screening out: 12\.34\.56\.78, which matches 188.8.131.52, but you want to be sure that it doesn’t match 184.108.40.2069 — so you set up your expression to be 12\.34\.56\.78$ . And if you want to be sure that it doesn’t match 5220.127.116.11 as well, you should use the beginning anchor ^ (how’s that for a reminder and a link back to the last part of this series), ^12\.34\.56\.78$
You should also be able to use it, Justin says, with the “on the fly” filter that you can do with every report (the little box near the top of every screen.) For example, if I wanted to know how many different variations of search terms end with my company’s name, I should be able to type in LunaMetrics$ in that little box on one of the search term reports (like Marketing Optimization > Search Engine Marketing > Overall Keyword conversion, and only see search terms like LunaMetrics or Call LunaMetrics or who the heck is LunaMetrics). I have never gotten that one to work. I do see potential there, though, because I can use a carat^ at the beginning of an in-report filter, like this: ^LunaMetrics, and I see all the search terms that start only with my company name.
And you can use it in the profile filters.
Am hoping one of the GA gurus will get on to say why the $ anchor doesn’t work in the in-report filters. After all, I am only taking lessons here, and sharing them with the world.
Dollars signs $
Question marks ?
Square brackets and dashes -
Plus signs +
Regular Expressions for Google Analytics: Now let’s Practice
RegEx and Good Greed