SlideShare a Scribd company logo
1 of 20
Download to read offline
Regular Expressions in
Google Analytics
Index
• Regular Expressions
• What and Why?
• Regular Expression Characters
• Backslash ()
• Pipe (|)
• Question Mark (?)
• Parentheses ()
• Square Brackets ([])
• Dashes (-)
• Curly Brackets ({})
• Dot (.)
• Plus Sign (+)
• Star (*)
• Dot-Star (.*)
• Caret (^)
• Dollar Sign ($)
Regular Expressions
(What & Why?)
Regular Expression / RegExp / RegEx
What is a Regular Expression?
 A regular expression is a special text string
for describing a search pattern.
 Searching with regular expressions enables
you to get results with just one search
instead of many searches.
Why use Regular Expressions?
In Google Analytics, you can use Regular
Expressions to -
 Create filters
 Create one goal that matches multiple goal
pages
 Fine tune your funnel steps so that you can
get exactly what you need
Regular Expression
Characters
Regular Expression Characters
There are 13 regular expressions in Google Analytics. This includes combinations of the most common regular
expressions -
Backslash : ()
 A backslash escapes a character.
 It turns the Regular Expression character into ordinary, plain characters.
For example:
Suppose /folder?pid=123 is your goal page. The problem we have is that the question mark
already has another use in Regular Expressions – but we need for it to be an ordinary
question mark. (We need it to be plain text.)
We can do it like this:
/folder?pid=123
The backslash in front of the question mark turns it into a plain question mark.
Pipe : (|)
 The pipe symbol is the simplest one and it means or.
 It is used to indicate that one of several possible choices can match.
For example:
1. Coke|Pepsi
A soft-drink blog might use that expression with their Google Analytics keyword report to
find all examples of searches that came to their blog using either the keyword Coke or the
keyword Pepsi.
2. Let’s say you have two thank-you pages, and you need to roll them up into one goal.
The first one is named thanks, and the second is named confirmation.
You could create your goal like this:
confirmation|thanks
That says, match either of those pages.
Question Mark : (?)
 The question mark is used to denote that either zero or one of the previous character
should be matched.
("The previous expression" means the character that comes right before the question
mark.)
For example:
1. Let's say that you have an economics website and you only want to look at the referrers
that have the word "labor" in their title. But some of those referrers come from countries
where they spell it "labour“.
You could create a filter like this: labou?r
It will match -
"labour" (which does have a "u," which is the previous expression) and
“labor” (which has zero of the previous expression, i.e. no "u" is included.)
Parentheses : ()
 Parentheses allow you to group characters together.
For example:
1. /folder(one|two)/thanks
This regular expression would match two URLs, folderone/thanks and foldertwo/thanks
Here we are allowing the Regular Expression to match either the thanks page in folderone
or the thanks page in foldertwo.
2. If a website has three thank-you pages: /thanks and /thankyou and /thanksalot
If we only want the /thanks and the /thanksalot pages to be part of our goal, we could do
it like this: /thanks(alot)?
This means, the target string must include /thanks, but alot is optional. So it matches both
/thanks and /thanksalot. And the /thankyou page will never get included, because there is
no s in its URL (so it doesn’t match the beginning of this RegEx, i.e. thanks).
Square Brackets : ([])
 Square brackets are used to define a set of characters.
(any one of the characters within the brackets can be matched.)
For example:
1. [Dd]istilled can be used to match both distilled and Distilled.
2. p[aiu]n will match pan, pin and pun. But it will not match pain, because that would
require us to use two items from the [aiu] list, and that is not allowed.
NOTE: Characters that are usually special, like $ and ?, no longer are special inside of square
brackets. The exceptions are the dash (-), the caret (^) and the backslash ().
Dashes : (-)
 Dashes are used to create a list of items.
 Square brackets can be used with dashes to create a powerful list.
For example:
1. Instead of creating a list like this [abcdefghijkl], you can create it like this: [a-l], and it
means the same thing - only one letter out of the list gets matched.
2. [a-z] – it will create a list of all lower-case letters in the English alphabet
3. [a-zA-Z0-9] – it will create a list of all lower-case and upper-case letters, and digits.
Curly Brackets / Braces : ({})
 Curly brackets or braces are used to define a specific number or range of repetitions.
 Braces repeat the last “piece” of information a specific number of times.
(When there are two numbers in the braces, such as {x,y}, it means, repeat the last “item”
at least x times & no more than y times. When there is only one number in the braces,
such as {z}, it means, repeat the last item exactly z times.)
For example:
Lots of companies want to take all visits from their IP address out of their analytics. So let’s
say that their IP addresses go from 123.145.167.0 to 123.145.167.99
Using braces, our regular expressions would be: 123.145.167.[0-9]{1,2}
Here we used a backslash to turn the special character dot into an everyday character dot, we
used brackets as well as dashes to define the set of allowable choices, i.e. the last “item”, and
we used braces to determine how many digits could be in the final part of the IP address.
Dot : (.)
 A dot matches any single character. It can be any single letter, number, symbol or space.
For example:
1. The Regular Expression .ead would match the strings read, bead, xead, 3ead, !ead etc.,
but not ead.
2. Let’s say your company owned a block of IP addresses: 123.45.67.250 to 123.45.67.255
You want to create a Regular Expression that will match the entire block, so that you can
take your company data out of your Google Analytics.
Since only the last character changes, you could do it with this expression:
123.45.67.25.
Plus Sign : (+)
 A plus sign matches one or more of the previous character.
For example:
1. abc+ would match abc, abcc, and anything like abccccccc.
2. [a]+ would match one or more occurrences of lowercase letter ‘a’.
3. gooo+gle would match goooogle, but never google.
4. Alternatively, you can build a list of Previous Items by using square brackets.
Like this: [abc]+
This will return a, ab, cab, c, b, bbbb, etc.
Star : (*)
 Star matches zero, one or more of the previous characters.
 They function just like plus signs, except they allow you to match ZERO (or more) of the
previous items, whereas plus signs require at least one match.
For example:
Let's say that your company uses five-digit part numbers in the format PN00000, and you
want to know how many people are searching for part number 34. Technically, the part
number is PN00034.
So, your regular expressions would be: PN0*34
This will display all the searches for PN034 and PN0034 and PN00034 and PN00000034 and
for that matter, PN34, since using the star means that the previous item doesn't need to be in
the search - zero or more of the previous items, it says.
Dot-Star : (.*)
 Dot-Star is a dot followed by a star.
 It matches zero or more random characters.
For example:
/folderone/.*index.php
This Regular Expression will match everything that starts with folderone/ and ends with
index.php. This means if you have pages in the /folderone directory that end with .html, they
won’t be a match to the above Regular Expression.
This means that the dot could match any letter in the alphabet, any digit, any number on your
keyboard. And the star right after it matches the ability of the dot to match any single
character, and keep on going (because it is zero or MORE) - so it ends up matching everything.
Caret : (^)
 Caret is used to denote the beginning of a regular expression.
For example:
If you’re trying to match all URLs within a specific directory of your site, you could use
^products/. This would match things like products/item1 and products/item2/description but
not a URL that doesn’t start with that string, such as support/products/.
 Caret also means NOT when used after the opening square bracket. (When you put a
caret inside square brackets at the very beginning, it means match only characters that
are not right after the caret)
For example:
1. [^0-9] means if the target string contains a digit, it is not a match.
2. [^a] means check for any single character other than the lowercase letter ‘a’.
Dollar Sign : ($)
 Dollar Sign is used to denote the end of a regular expression or ending of a line.
For example:
1. Colou?r$ would check for a pattern which ends with ‘Color’ or ‘Colour’.
2. product-price.php$ would check for a pattern which ends with ‘product-price.php’
Thank You

More Related Content

What's hot

Php String And Regular Expressions
Php String  And Regular ExpressionsPhp String  And Regular Expressions
Php String And Regular Expressionsmussawir20
 
Finaal application on regular expression
Finaal application on regular expressionFinaal application on regular expression
Finaal application on regular expressionGagan019
 
Regular Expressions in PHP, MySQL by programmerblog.net
Regular Expressions in PHP, MySQL by programmerblog.netRegular Expressions in PHP, MySQL by programmerblog.net
Regular Expressions in PHP, MySQL by programmerblog.netProgrammer Blog
 
Lecture 4 - Comm Lab: Web @ ITP
Lecture 4 - Comm Lab: Web @ ITPLecture 4 - Comm Lab: Web @ ITP
Lecture 4 - Comm Lab: Web @ ITPyucefmerhi
 
Introduction to Regular Expressions
Introduction to Regular ExpressionsIntroduction to Regular Expressions
Introduction to Regular ExpressionsJesse Anderson
 
Java: Regular Expression
Java: Regular ExpressionJava: Regular Expression
Java: Regular ExpressionMasudul Haque
 
Regular Expressions and You
Regular Expressions and YouRegular Expressions and You
Regular Expressions and YouJames Armes
 
N-Queens Combinatorial Problem - Polyglot FP for Fun and Profit - Haskell and...
N-Queens Combinatorial Problem - Polyglot FP for Fun and Profit - Haskell and...N-Queens Combinatorial Problem - Polyglot FP for Fun and Profit - Haskell and...
N-Queens Combinatorial Problem - Polyglot FP for Fun and Profit - Haskell and...Philip Schwarz
 

What's hot (12)

Php String And Regular Expressions
Php String  And Regular ExpressionsPhp String  And Regular Expressions
Php String And Regular Expressions
 
Finaal application on regular expression
Finaal application on regular expressionFinaal application on regular expression
Finaal application on regular expression
 
Regular Expressions in PHP, MySQL by programmerblog.net
Regular Expressions in PHP, MySQL by programmerblog.netRegular Expressions in PHP, MySQL by programmerblog.net
Regular Expressions in PHP, MySQL by programmerblog.net
 
Les08
Les08Les08
Les08
 
Lecture 4 - Comm Lab: Web @ ITP
Lecture 4 - Comm Lab: Web @ ITPLecture 4 - Comm Lab: Web @ ITP
Lecture 4 - Comm Lab: Web @ ITP
 
2013 - Andrei Zmievski: Clínica Regex
2013 - Andrei Zmievski: Clínica Regex2013 - Andrei Zmievski: Clínica Regex
2013 - Andrei Zmievski: Clínica Regex
 
Python Regular Expressions
Python Regular ExpressionsPython Regular Expressions
Python Regular Expressions
 
Introduction to Regular Expressions
Introduction to Regular ExpressionsIntroduction to Regular Expressions
Introduction to Regular Expressions
 
Java: Regular Expression
Java: Regular ExpressionJava: Regular Expression
Java: Regular Expression
 
Regular Expressions
Regular ExpressionsRegular Expressions
Regular Expressions
 
Regular Expressions and You
Regular Expressions and YouRegular Expressions and You
Regular Expressions and You
 
N-Queens Combinatorial Problem - Polyglot FP for Fun and Profit - Haskell and...
N-Queens Combinatorial Problem - Polyglot FP for Fun and Profit - Haskell and...N-Queens Combinatorial Problem - Polyglot FP for Fun and Profit - Haskell and...
N-Queens Combinatorial Problem - Polyglot FP for Fun and Profit - Haskell and...
 

Similar to Regular Expressions in Google Analytics

Google Search
Google SearchGoogle Search
Google Searchjjs1981
 
Regular expressions
Regular expressionsRegular expressions
Regular expressionsRaghu nath
 
Regular Expression in Action
Regular Expression in ActionRegular Expression in Action
Regular Expression in ActionFolio3 Software
 
Regular Expressions 2007
Regular Expressions 2007Regular Expressions 2007
Regular Expressions 2007Geoffrey Dunn
 
Introduction_to_Regular_Expressions_in_R
Introduction_to_Regular_Expressions_in_RIntroduction_to_Regular_Expressions_in_R
Introduction_to_Regular_Expressions_in_RHellen Gakuruh
 
Regular expressions
Regular expressionsRegular expressions
Regular expressionskeeyre
 
Regular expressions
Regular expressionsRegular expressions
Regular expressionsEran Zimbler
 
What is the general format for a Try-Catch block Assume that amt l .docx
 What is the general format for a Try-Catch block  Assume that amt l .docx What is the general format for a Try-Catch block  Assume that amt l .docx
What is the general format for a Try-Catch block Assume that amt l .docxajoy21
 
Textpad and Regular Expressions
Textpad and Regular ExpressionsTextpad and Regular Expressions
Textpad and Regular ExpressionsOCSI
 
New features in abap
New features in abapNew features in abap
New features in abapSrihari J
 
Introduction To Regex in Lasso 8.5
Introduction To Regex in Lasso 8.5Introduction To Regex in Lasso 8.5
Introduction To Regex in Lasso 8.5bilcorry
 
Javascript part1
Javascript part1Javascript part1
Javascript part1Raghu nath
 

Similar to Regular Expressions in Google Analytics (20)

Regex lecture
Regex lectureRegex lecture
Regex lecture
 
Boolean operators
Boolean operatorsBoolean operators
Boolean operators
 
Google Search
Google SearchGoogle Search
Google Search
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
Regular Expression in Action
Regular Expression in ActionRegular Expression in Action
Regular Expression in Action
 
2.regular expressions
2.regular expressions2.regular expressions
2.regular expressions
 
Amusing C#
Amusing C#Amusing C#
Amusing C#
 
Regular Expressions 2007
Regular Expressions 2007Regular Expressions 2007
Regular Expressions 2007
 
Introduction_to_Regular_Expressions_in_R
Introduction_to_Regular_Expressions_in_RIntroduction_to_Regular_Expressions_in_R
Introduction_to_Regular_Expressions_in_R
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
What is the general format for a Try-Catch block Assume that amt l .docx
 What is the general format for a Try-Catch block  Assume that amt l .docx What is the general format for a Try-Catch block  Assume that amt l .docx
What is the general format for a Try-Catch block Assume that amt l .docx
 
Template
TemplateTemplate
Template
 
Textpad and Regular Expressions
Textpad and Regular ExpressionsTextpad and Regular Expressions
Textpad and Regular Expressions
 
Unix
UnixUnix
Unix
 
Quick start learn dax basics in 30 minutes
Quick start   learn dax basics in 30 minutesQuick start   learn dax basics in 30 minutes
Quick start learn dax basics in 30 minutes
 
New features in abap
New features in abapNew features in abap
New features in abap
 
FinalReport
FinalReportFinalReport
FinalReport
 
Introduction To Regex in Lasso 8.5
Introduction To Regex in Lasso 8.5Introduction To Regex in Lasso 8.5
Introduction To Regex in Lasso 8.5
 
Javascript part1
Javascript part1Javascript part1
Javascript part1
 

Recently uploaded

Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsPrecisely
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsAndrey Dotsenko
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 

Recently uploaded (20)

Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power Systems
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 

Regular Expressions in Google Analytics

  • 2. Index • Regular Expressions • What and Why? • Regular Expression Characters • Backslash () • Pipe (|) • Question Mark (?) • Parentheses () • Square Brackets ([]) • Dashes (-) • Curly Brackets ({}) • Dot (.) • Plus Sign (+) • Star (*) • Dot-Star (.*) • Caret (^) • Dollar Sign ($)
  • 4. Regular Expression / RegExp / RegEx What is a Regular Expression?  A regular expression is a special text string for describing a search pattern.  Searching with regular expressions enables you to get results with just one search instead of many searches. Why use Regular Expressions? In Google Analytics, you can use Regular Expressions to -  Create filters  Create one goal that matches multiple goal pages  Fine tune your funnel steps so that you can get exactly what you need
  • 6. Regular Expression Characters There are 13 regular expressions in Google Analytics. This includes combinations of the most common regular expressions -
  • 7. Backslash : ()  A backslash escapes a character.  It turns the Regular Expression character into ordinary, plain characters. For example: Suppose /folder?pid=123 is your goal page. The problem we have is that the question mark already has another use in Regular Expressions – but we need for it to be an ordinary question mark. (We need it to be plain text.) We can do it like this: /folder?pid=123 The backslash in front of the question mark turns it into a plain question mark.
  • 8. Pipe : (|)  The pipe symbol is the simplest one and it means or.  It is used to indicate that one of several possible choices can match. For example: 1. Coke|Pepsi A soft-drink blog might use that expression with their Google Analytics keyword report to find all examples of searches that came to their blog using either the keyword Coke or the keyword Pepsi. 2. Let’s say you have two thank-you pages, and you need to roll them up into one goal. The first one is named thanks, and the second is named confirmation. You could create your goal like this: confirmation|thanks That says, match either of those pages.
  • 9. Question Mark : (?)  The question mark is used to denote that either zero or one of the previous character should be matched. ("The previous expression" means the character that comes right before the question mark.) For example: 1. Let's say that you have an economics website and you only want to look at the referrers that have the word "labor" in their title. But some of those referrers come from countries where they spell it "labour“. You could create a filter like this: labou?r It will match - "labour" (which does have a "u," which is the previous expression) and “labor” (which has zero of the previous expression, i.e. no "u" is included.)
  • 10. Parentheses : ()  Parentheses allow you to group characters together. For example: 1. /folder(one|two)/thanks This regular expression would match two URLs, folderone/thanks and foldertwo/thanks Here we are allowing the Regular Expression to match either the thanks page in folderone or the thanks page in foldertwo. 2. If a website has three thank-you pages: /thanks and /thankyou and /thanksalot If we only want the /thanks and the /thanksalot pages to be part of our goal, we could do it like this: /thanks(alot)? This means, the target string must include /thanks, but alot is optional. So it matches both /thanks and /thanksalot. And the /thankyou page will never get included, because there is no s in its URL (so it doesn’t match the beginning of this RegEx, i.e. thanks).
  • 11. Square Brackets : ([])  Square brackets are used to define a set of characters. (any one of the characters within the brackets can be matched.) For example: 1. [Dd]istilled can be used to match both distilled and Distilled. 2. p[aiu]n will match pan, pin and pun. But it will not match pain, because that would require us to use two items from the [aiu] list, and that is not allowed. NOTE: Characters that are usually special, like $ and ?, no longer are special inside of square brackets. The exceptions are the dash (-), the caret (^) and the backslash ().
  • 12. Dashes : (-)  Dashes are used to create a list of items.  Square brackets can be used with dashes to create a powerful list. For example: 1. Instead of creating a list like this [abcdefghijkl], you can create it like this: [a-l], and it means the same thing - only one letter out of the list gets matched. 2. [a-z] – it will create a list of all lower-case letters in the English alphabet 3. [a-zA-Z0-9] – it will create a list of all lower-case and upper-case letters, and digits.
  • 13. Curly Brackets / Braces : ({})  Curly brackets or braces are used to define a specific number or range of repetitions.  Braces repeat the last “piece” of information a specific number of times. (When there are two numbers in the braces, such as {x,y}, it means, repeat the last “item” at least x times & no more than y times. When there is only one number in the braces, such as {z}, it means, repeat the last item exactly z times.) For example: Lots of companies want to take all visits from their IP address out of their analytics. So let’s say that their IP addresses go from 123.145.167.0 to 123.145.167.99 Using braces, our regular expressions would be: 123.145.167.[0-9]{1,2} Here we used a backslash to turn the special character dot into an everyday character dot, we used brackets as well as dashes to define the set of allowable choices, i.e. the last “item”, and we used braces to determine how many digits could be in the final part of the IP address.
  • 14. Dot : (.)  A dot matches any single character. It can be any single letter, number, symbol or space. For example: 1. The Regular Expression .ead would match the strings read, bead, xead, 3ead, !ead etc., but not ead. 2. Let’s say your company owned a block of IP addresses: 123.45.67.250 to 123.45.67.255 You want to create a Regular Expression that will match the entire block, so that you can take your company data out of your Google Analytics. Since only the last character changes, you could do it with this expression: 123.45.67.25.
  • 15. Plus Sign : (+)  A plus sign matches one or more of the previous character. For example: 1. abc+ would match abc, abcc, and anything like abccccccc. 2. [a]+ would match one or more occurrences of lowercase letter ‘a’. 3. gooo+gle would match goooogle, but never google. 4. Alternatively, you can build a list of Previous Items by using square brackets. Like this: [abc]+ This will return a, ab, cab, c, b, bbbb, etc.
  • 16. Star : (*)  Star matches zero, one or more of the previous characters.  They function just like plus signs, except they allow you to match ZERO (or more) of the previous items, whereas plus signs require at least one match. For example: Let's say that your company uses five-digit part numbers in the format PN00000, and you want to know how many people are searching for part number 34. Technically, the part number is PN00034. So, your regular expressions would be: PN0*34 This will display all the searches for PN034 and PN0034 and PN00034 and PN00000034 and for that matter, PN34, since using the star means that the previous item doesn't need to be in the search - zero or more of the previous items, it says.
  • 17. Dot-Star : (.*)  Dot-Star is a dot followed by a star.  It matches zero or more random characters. For example: /folderone/.*index.php This Regular Expression will match everything that starts with folderone/ and ends with index.php. This means if you have pages in the /folderone directory that end with .html, they won’t be a match to the above Regular Expression. This means that the dot could match any letter in the alphabet, any digit, any number on your keyboard. And the star right after it matches the ability of the dot to match any single character, and keep on going (because it is zero or MORE) - so it ends up matching everything.
  • 18. Caret : (^)  Caret is used to denote the beginning of a regular expression. For example: If you’re trying to match all URLs within a specific directory of your site, you could use ^products/. This would match things like products/item1 and products/item2/description but not a URL that doesn’t start with that string, such as support/products/.  Caret also means NOT when used after the opening square bracket. (When you put a caret inside square brackets at the very beginning, it means match only characters that are not right after the caret) For example: 1. [^0-9] means if the target string contains a digit, it is not a match. 2. [^a] means check for any single character other than the lowercase letter ‘a’.
  • 19. Dollar Sign : ($)  Dollar Sign is used to denote the end of a regular expression or ending of a line. For example: 1. Colou?r$ would check for a pattern which ends with ‘Color’ or ‘Colour’. 2. product-price.php$ would check for a pattern which ends with ‘product-price.php’