Show Menu

Google Analytics Regular Expressions Cheat Sheet by Jay Taylor

A list of Regular Expression functionality supported by Google Analytics

Anchors

^Start of line
$End of line

Character Classes

\sWhite space character
\SNon-white space character
\dDigit character
\DNon-digit character
\wWord
\WNon-word (e.g. punctu­ation, spaces)

Metach­ara­cters (must be escaped)

^[]
$()
.{}
*+?
\|-

GA Filter group accessors

$AxAccess group x in field A (e.g. $A1)
$BxAccess group x in field B (e.g. $B1)
 

Quanti­fiers

*Zero or more (greedy)
*?Zero or more (lazy)
+One or more (greedy)
+?One or more (lazy)
?Zero or one (greedy)
??Zero or one (lazy)
{X}Exactly X (e.g. 3)
{X,}X or more, (e.g. 3)
{X, Y}Between X and Y (e.g. 3 and 5) (lazy)

Ranges and Groups

.Any character
(a|b)a or b (case sensitive)
(...)Group, e.g. (keyword)
(?:...)Passive group, e.g. (?:key­word)
[abc]Range (a or b or c)
[^abc]Negative range (not a or b or c)
[A-Z]Uppercase letter between A and Z
[a-z]Lowercase letter between a and z
[0-7]Digit between 0 and 7
 

Sample Patterns

^/di­rec­tor­y/(.*)
Any page URLs starting with /direc­tory/

(bra­nd\­s*?­term)
Brand term with or without whitespace between words

^br­and­\s+­[^cf]
Key phrases beginning with 'brand' and the second word not starting with c or f

\.as­px$
URLs ending in '.aspx'

ORDE­R\-­\d{6}
"OR­DER­-" followed by a six digit ID

(?:\­?|&)u­tm=­([^­&$­]+)
Value of 'utm' querys­tring parameter
 

Share This Cheat Sheet!

Favourited by 14 Members:

afdesigns Chilly_Bang multistreams Dranzz cthumerelle parastudio Matmal The_Frail schrodervictor fire9 maintainweb kagua tonicarr Tim Leighton-Boyce

Comments

DaveChild DaveChild, 08:11 11 Feb 12

Great cheat sheet, Jay, especially the sample patterns!

Jay Taylor Jay Taylor, 18:10 11 Feb 12

Thanks Dave! Obviously it's based heavily on your main RE one, I'm really hoping Google will add support for assertions in the future, would make life so much easier!

Brian CLifton Brian CLifton, 09:59 23 Feb 12

Nice cheat sheet Jay

I don't think you need this one:
(bra­nd\­s*?­term)

as just (brand) will work, no? That is, (brand) will match:
"brandterm", and "brand term"

Sean Hughes Sean Hughes, 09:59 23 Feb 12

Excellent cheat sheet Jay, really helpful.

Tim Leighton-Boyce Tim Leighton-Boyce, 10:07 23 Feb 12

This is really helpful. Thank you Jay. Just the kind of resource we need.

Modi Modi, 15:19 26 Feb 12

Good stuff Jay! Thanks for sharing.

Marc Beharry Marc Beharry, 14:44 6 Aug 12

thanks much Jay!!

Chaitanya Chaitanya, 14:44 6 Aug 12

Great information, really awesome..

Surbhi Surbhi, 13:16 6 Mar 13

Cant thank you enough for this amazing resource!

gabe gabe, 17:16 26 Mar 13

I do have a file name LIKE maxfile_[A-Z]_[0-9]{6} and I want to use a wild card like ^maxfile_ but it does not work

James James, 16:30 5 Apr 13

Hi guys,

Just a short question on using the right regular expression. I want to create a funnel which has to gather information on different URL's. The one thing that all the URLs have in common is their last part. For example, i want to include al these URL's in one step of a funnel:

book/cabin/step4
orange/keyboard/stairs/step4
ball/step4

> They all have the same last part; 'step4'. Which regulare expression do i have to use to collect the data of all these different pages?

Hope you can help me!
James

Zaib Zaib, 14:18 13 Feb 14

@James:

user this regex:
/step4$

The Battosai The Battosai, 15:09 13 Feb 14

James,

That would be
/step4$

Gaurav Gaurav, 12:06 14 Feb 14

What about "#" ?
i need to create the rule that only fires up on deep links.
Any help would be appreciated.

Jackson Oh Jackson Oh, 09:03 26 Feb 14

Thank you so much for the cheat sheet!

Scott Scott, 09:58 17 Mar 14

I have a goal that could encompass any number after /offer. Would this be correct?

/offer\d

Thanks

Ana Ana, 10:14 4 Jun 14

+ Información y Documentación en Español http://contadordecaracteres.info/prueba-expresiones-regulares.html

Jasper Jasper, 17:48 5 Jun 14

I've have an question i have the following link:

/brand/showroom/(?:brand)/(.*)/(.*)/brand-occasions/(.*)/overzicht

now in my google goals he's only showing the visits

(?:brand) containing brand

but i want to exclude the word brand instead of showing it

how can i fix that?

Christopher Christopher, 08:29 9 Oct 14

This is cool

Im looking to do a GA filter to filter out several versions of internet explorer


Currently doing One at a time

and have 9\.11 as the pattern

is that correct?

igor igor, 16:09 12 Nov 14

hi! I have page

site.com/p/413121892/buy?getseaid=b6b6457d__-1936669385__

i need to set a goal with "buy" or "b6b6457d__-1936669385__" how to do that? thanks

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.