Regular Expressions Pt. V: Question Marks ?
So I continue here with my Regular Expressions (“RegEx”) lessons. I am learning RegEx only because so many customers use Google Analytics, which throws the code at the customer with very little explanation.
This next lesson is about the question mark. This time, Google does a pretty good job of meaning what they say:
? Match zero or one of the previous expression
When they say, “The previous expression,” they mean, the character that comes right before the question mark. Since that is still pretty opaque, let me shine some light here.
Let’s say that you have an economics website and you only want to look at the referrers that have the word “labor” in their title. But some of those referrers come from non-US countries where they spell it “labour.” You could create a filter like this: labou?r
That way, it will match “labour” (which does have a “u,” which is the previous expression) and labor (which has zero of the previous expression, i.e. no “u” is included.)
You cannot use it like this : labo?r, or at least, not for the same purpose. It’s not a wildcard that you stick in between the o and the r to match any letter. The only matches would be to “labor” (zero of the previous expression) and “labr” (Thanks Serge for catching my error.)
Dollars signs $
Question marks ?
Square brackets and dashes -
Plus signs +
Regular Expressions for Google Analytics: Now let’s Practice
RegEx and Good Greed
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.