13.07.2015 Views

ebook on regular expressions for Google Analytics - LunaMetrics

ebook on regular expressions for Google Analytics - LunaMetrics

ebook on regular expressions for Google Analytics - LunaMetrics

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

anchorsThE c areT^When you use a caret in your Regular Expressi<strong>on</strong>,you <strong>for</strong>ce the Expressi<strong>on</strong> to match <strong>on</strong>ly strings that start exactlythe same way your RegEx does.I see carets misused all the time <strong>on</strong> various <strong>Google</strong> <strong>Analytics</strong> helpgroups. It goes something like this:“I want to include <strong>on</strong>ly subfolder2 in my profile. My URLs looklike: http://www.mysite.com/folder1/subfolder2/index.html. Icreated the include filter and the Regular Expressi<strong>on</strong>, which lookslike this: ^/subfolder2/index\.html. Why isn’t it working?”The reas<strong>on</strong> it doesn’t work is that <strong>Google</strong> <strong>Analytics</strong> starts readingyour URL right after the .com (or .edu, or .net, as it were). The GAsees the above as /folder1/subfolder2/index.html. So whenthe pers<strong>on</strong> who wrote the questi<strong>on</strong> above starts his RegEx with^/subfolder2, he shoots himself in the foot. In the eyes of GA,/folder1 comes be<strong>for</strong>e /subfolder2, yet the caret mandates that/subfolder2 must be at the beginning of the target string. (Andit’s not! So it will never match.)a D va N Ced tI pWhen you put a caret inside square brackets at thevery beginning, it means match <strong>on</strong>ly characters thatare not right after the caret. So [^0-9] meansif the target string c<strong>on</strong>tains a digit,it is not a match.19

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!