




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





Drawn from: support.google.com/analytics
Analytics supports regular expressions so you can create more flexible definitions for things like view filters, goals, segments, audiences, content groups, and channel groupings.
In the context of Analytics, regular expressions are specific sequences of characters that broadly or narrowly match patterns in your Analytics data.
For example, if you wanted to create a view filter to exclude site data generated by your own employees, you could use a regular expression to exclude any data from the entire range of IP addresses that serve your employees. Let’s say those IP addresses range from 198.51.100.1 - 198.51.100.25. Rather than enter 25 different IP addresses, you could create a regular expression like 198.51.100.\d* that matches the entire range of addresses.
Or if you wanted to create a view filter that included only campaign data from two different cities, you could create a regular expression like San Francisco|New York (San Francisco or New York).
Wildcards
. Matches any single character (letter, number or symbol) 1. matches 10, 1A
1.1 matches 111, 1A
Examples
? Matches the preceding character 0 or 1 times 10? matches 1, 10
Examples
Examples
Examples
| Creates an OR match
Do not use at the end of an expression
1|10 matches 1, 10
Examples
Anchors
^ Matches the adjacent characters at the beginning of a string
^10 matches 10, 100, 10x
^10 does not match 110, 110x
Examples
$ Matches the adjacent characters at the end of a string
10$ matches 110, 1010
10$ does not match 100, 10x
Examples
Groups
( ) Matches the enclosed characters in exact order anywhere in a string
Also used to group other expressions
(10) matches 10, 101, 1011
([0-9]|[a-z]) matches any number or lower- case letter
Examples
[ ] Matches the enclosed characters in any order anywhere in a string
[10] matches 012, 123, 202, 120, 210
Examples
[0-9] matches any number 0 through 9
Examples
Escape
\ Indicates that the adjacent character should be interpreted literally rather than as a regex metacharacter
. indicates that the adjacent dot should be interpreted as a period or decimal rather than as a wildcard.
216 .239.32.34 matches
City matches regex London|Paris
You can also use the pipe within parentheses. For example, here’s another way to create the expression to match your beach-sandal SKUs:
(MN|WM)BS\d+
(MN OR WM) BS (character code for beach sandals) \d (numeric character)
Use square brackets to create a set of characters to match.
When you include a series of characters in brackets, your expression matches 1 of those characters.
For example, the expression PART[123] matches:
PART PART PART
The expression doesn’t match:
PART PART PART
Use the hyphen along with the brackets to create a range of characters to match.
For example, if you need to match any uppercase letter, you can specify [A-Z].
If you need to match any digit, you can specify [0-9].
If you needed to match all of the part numbers above, you could use the following expression:
[A-Z]+[0-9]+
[A-Z] (matches any uppercase letter)
The question mark (?) matches the preceding character 0 or 1 times.
For example, 10? matches:
1 10
Example
Match an IP address with 1 or 2 digits in the last section.
For example, 216.239.32.\d\d? matches:
216.239.32. 216.239.32.
This example uses the backslash to escape the decimal, and uses \d to match any digit.
The plus sign (+) matches the preceding character 1 or more times.
For example, 10+ matches:
10 100 1000 etc.
Example
Match an IP address with 1 or more digits in the last section.
For example, 216.239.32.\d+ matches:
216.239.32. 216.239.32. 216.239.32.
This example uses the backslash to escape the decimal, and uses \d to match any digit.
The asterisk or star matches the preceding character 0 or more times.
For example, 10* matches:
1 10 100 1000
sees a backslash, it knows that it should interpret the next character literally. A regular expression to match the IP address 0.0.0.0 would be:
0.0.0.
Use the backslash to escape any special character and interpret it literally; for example:
\ (escapes the backslash) [ (escapes the bracket) { (escapes the curly brace) . (escapes the dot)
Use the caret to match the following adjacent characters at the beginning of a string.
For example, ^St matches:
St art here St and here St op here
However, ^St doesn’t match:
1 Start here 2 Stand here 3 Stop here
The preceding 3 lines start with a digit and a space, not with the letters “St”.
Use this type of regular expression to create segments, filters, or goal steps that match a URI. For example, if you need to isolate data for a particular directory of pages, you can use expressions like:
^/mens/ (matches www.example.com /mens/ ) ^/womens/ (matches www.example.com /womens/ )
Use the dollar sign to match the preceding, adjacent characters at the end of a string.
For example, end$ matches:
Temporarily susp end We’re going off the deep end Match the characters that prep end
However, end$ doesn’t match:
Temporarily suspend. We’re going off the deep end. Match the characters that prepend.
The preceding 3 lines all end with nd. rather than the end characters you’re matching with the regular expression.
Use this type of regular expression to create segments, filters, or goal steps that match a URI. For example, if you’re you’re testing the efficacy of a new .htm version page vs. an older .html version, you can identify the versions separately with regular expressions like:
email-signup.htm$ email-signup.html$
Use the slash to escape the dot and ensure that it is interpreted literally.
An easy way to test a regular expression on your own data is to navigate directly to a report in your view and use the advanced table-filter feature.
For example, to try out a regular expression that filters pages: