The dot star isn’t a regular expression, but a combination of two regular expressions used together. It is so useful that it’s often thought of as a character in
its own right. It’s useful, but also powerful and can be a big contributor to errors and problems when using RegEx.
The Dot Star will match absolutely anything. The dot matches any single character, and the star makes it infinite. So if you simple filtered by ‘.*’ you would get the same results as no filter at all. So why would you want to use it? Because it’s a brilliant wildcard for filtering in Google Analytics.
Examples of Dot Star in Regular Expressions:
My website at work is published in 22 languages. The publications all have a similar URL structure, with a country code prefix , then a section, ‘Schools’, ‘Courses’ etc, then the name of the pages themselves.
at the examples below:
The dot star is flexible enough to use for a variety of ‘wildcard’ filters:
‘/.*/schools/index.html’ for schools index pages on all publications.
‘/fr/courses/.*’ for all courses pages on the French publication.
‘/fr/.*/index.html’ for all index pages on the French publication.
I also use dot star to find broken links on pages on my site that end in page not found 404 errors. Our setup means these appear in content reports like the following:
‘err.html?errorpath=(URI the user was trying to get to)’
You can find all the pages easily enough as follows:
But if you wanted to look at what pages in my schools section were resulting in errors, I’d use dot star.
‘err.html.*/schools/.*’ for all pages in the schools section in all publications.
‘err.html?errorpath/fr/.*’ for all pages in the french publication.
If I’m using regex for something less transient, like an advanced filter I’m planning to distribute, I always test it in the filter on the report I’m going to use. The dot star often includes items in my results that I wasn’t expecting. Don’t leave it to chance, and always test it out, often your code will only need a quick tweak to sort it out.
Let me know if you use the dot star and find it useful! Are there any other useful applications I haven’t mentioned above? I’d love to hear from you…
Links to the rest of the series:
RegEx 1: Introduction
RegEx 2: Pipe
RegEx 3: Brackets
RegEx 4: Question Mark
RegEx 5: Backslash
RegEx 6: Plus Sign
RegEx 7: Dot
RegEx 8: Star
RegEx 9: Dot Star – You are here!
RegEx 10: Caret
RegEx 11: Dollar Sign
RegEx 12: Square Brackets
RegEx 13: 5 Great Places to use RegEx