Regular expressions can be hard to understand, even for the most seasoned propellerhead. I initially wrote this tool to help myself. The concept is simple – paste in a block of text and write a regular expression to see what matches. I’ve released the tool and hope you find it useful tool. Find it here.
What is a regular expression?
Regular expressions (regex) are strings of characters that, when combined, form a very specific and powerful search pattern. At ObservePoint, we use regex as part of data validation methods, including detecting tags on the web. We use regex to match varied requests but group them as under the same tag type. Along with matching, regular expressions also allow us to extract data from requests, including variables, accounts, versions, and more. Regular expressions are used every day here at ObservePoint, both internally and by our customers. Though they can be complex, they are a useful tool for matching text data.
Many analytics tools support regular expressions in a variety of ways. A common use case is as a data filter, when a more simple include/exclude type of filter is not powerful enough. For example, you may want to filter on a product variable, looking for shirts or sweaters. In this case, the following regular expression would be useful:
(shirt|sweater)
The pipe (|) character in the aforementioned is saying, match ‘shirt’ OR ‘sweater’. If we tweaked the previous slightly, we come up with something even more powerful:
summer-(shirt|sweater)
Now we are matching some input on something with summer, but followed by shirt or sweater. So ‘summer-shirt’ OR ‘summer-sweater’. You can see this example tested and working in the tool here.
Regular expressions are a powerful tool for both programming and search. For more information on regular expressions, including their use, syntax, etc., see this helpful Google Analytics resource.
About the Author
LinkedIn More Content by Alan Feuerlein