Regular expressions (regex) are one of the most powerful tools in your Data Studio and Google Analytics toolkit — and one of the most underused. A regex is a sequence of characters that defines a search pattern, letting you filter, match, and manipulate data in ways that simple text filters can't touch.
This guide covers every major regex symbol with practical examples from analytics and reporting.
Symbol Reference
Dot (.) — Match any character
The dot is a wildcard that matches any single character. Chain multiple dots to match multiple characters.
Example: .age matches "page", "rage", "cage" — any three-character string ending in "age".
Question Mark (?) — Optional character
Makes the preceding character optional. Useful for handling spelling variants or number formats.
Example: miss?pelling matches both "misspelling" and "mispelling".
Plus (+) — One or more
The preceding character must appear at least once.
Example: 10+ matches "10", "100", "1000", "10000" — any string starting with 1 followed by one or more zeros.
Asterisk (*) — Zero or more
Similar to plus, but allows zero occurrences of the preceding character.
Pipe (|) — OR
Matches either expression on either side of the pipe.
Example: /gift/|/giftcard/ matches URLs containing either "/gift/" or "/giftcard/".
Caret (^) — Start of string
Anchors the match to the beginning of the string.
Example: ^/giftcard/ only matches pages whose path starts with "/giftcard/" — it won't match "/shop/giftcard/".
Dollar ($) — End of string
Anchors the match to the end of the string.
Example: giftcard$ matches strings ending with "giftcard".
Parentheses () — Group expressions
Groups characters and matches them in exact sequence.
Example: A(B|C) matches "AB" or "AC".
Square Brackets [] — Character list
Matches any single character within the brackets.
Example: product[ABC] matches "productA", "productB", or "productC" — but not "productD".
Curly Brackets {} — Repetition count
Repeats the preceding character a specific number of times. Use {n} for exactly n times, {min,max} for a range.
Example: \d{2,5} matches any sequence of 2 to 5 digits.
Dash (-) — Character range
Used inside square brackets to define a range.
Examples:
[A-Z]matches any uppercase letter[0-9]matches any single digit[a-z0-9]matches any lowercase letter or digit
Backslash (\) — Escape character
Escapes the next character so it's treated as a literal rather than a regex function.
Example: 123\.456\.10\.10 searches for a literal IP address with dots — without the backslashes, the dots would be wildcards.
Shorthand Character Classes
| Pattern | Matches |
|---------|---------|
| \w | Any word character (letters, digits, underscore) |
| \d | Any digit (0–9) |
| \s | A whitespace character (space, tab) |
Useful Combinations
Dot + Asterisk (.*) — Match anything
The most flexible pattern: .* matches any character any number of times (including zero).
Example: /sign-up/.*\/thank-you matches any URL that starts with "/sign-up/" and ends with "/thank-you", regardless of what's in between — so both /sign-up/newsletter/thank-you and /sign-up/mailing/thank-you are captured.
Word Count Matching
Use these patterns to segment queries by length — useful for separating short-tail from long-tail keywords:
- One word:
^\w*$ - Two words:
^\w*\s\w*$ - Three words:
^\w*\s\w*\s\w*$
IP Address Filtering
To exclude internal traffic, filter by IP address:
Exact address: 123\.456\.789\.10
Range (0–99): 123\.456\.789\.[0-9]{1,2}
Complex range (0–25 and 55–70):
123\.456\.789\.([0-9]|1[0-9]|2[0-5]|5[5-9]|6[0-9]|70)
Using digit shorthand: 123\.456\.789\.\d
Email Address Pattern
For matching or validating email addresses:
^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$
Regular expressions reward the time invested in learning them. Even knowing a handful of patterns — caret, dollar, pipe, dot-asterisk — dramatically expands what you can do with filters in Data Studio, Analytics, and Tag Manager. Bookmark this page and refer back to it as you build your reports.
