Analytics
2.3K members online now
Understand information in your reports and troubleshoot reporting issues such as self-referrals, (not set) data, and inaccurate information
 
Guide Me
star_border
Reply

RegEx for URL structure

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

I have read the Google guide to RegEx with Google Analytics and I am struggling to create the pattern I want.

 

I want to only capture data of all URL's that are only 1 deep.
Example:
domain-name.com/level-1.html
 
Do not capture:
domain-name/level-1/level-2.html
 
I tried the following regEx:
\/(\w+\-){1,}\w+\.html
 
But this seems to capture different depths.
 
How do I only capture one depth deep?
1 Expert replyverified_user
1 ACCEPTED SOLUTION

Accepted Solutions
Marked as Best Answer.
Solution
Accepted by topic author Worship D
January 2017

RegEx for URL structure

Rising Star
# 2
Rising Star

Hi Worship D,

 

Try a caret to open  ^  (starts with)

 

e.g.  ^\/(\w+\-){1,}\w+\.html

 

You can also end with a $ if you are not going to have any parameters, etc after .html

 

Best,

 

Theo Bennett

Analytics Evangelist at MoreVisibility | Contact Me
Connect on LinkedIn

View solution in original post

Marked as Best Answer.
Solution
Accepted by topic author Worship D
January 2017

RegEx for URL structure

Rising Star
# 2
Rising Star

Hi Worship D,

 

Try a caret to open  ^  (starts with)

 

e.g.  ^\/(\w+\-){1,}\w+\.html

 

You can also end with a $ if you are not going to have any parameters, etc after .html

 

Best,

 

Theo Bennett

Analytics Evangelist at MoreVisibility | Contact Me
Connect on LinkedIn

RegEx for URL structure

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭

In my experience with RegEx in Data Studio, I've found that you need a double "\\" instead of the regular single "\" to cancel punctuation marks as RegEx. I have no idea why they decided to do that. It took me a long while to find out.

 

Anyways, try double \\ instead Smiley Happy

 

Cheers

RegEx for URL structure

Rising Star
# 4
Rising Star

@oscar o That's true for Data Studio but this was about, and posted in, Google Analytics not Data Studio.

Analytics Evangelist at MoreVisibility | Contact Me
Connect on LinkedIn

RegEx for URL structure

Visitor ✭ ✭ ✭
# 5
Visitor ✭ ✭ ✭

You're right. I guess I got lost while searching for help with a Data Studio issue in the same subject! Maybe you can help me with it? https://www.en.advertisercommunity.com/t5/Data-Studio/Same-Regex-filters-showing-different-numbers-f...

RegEx for URL structure

Rising Star
# 6
Rising Star

Hey @oscar o,

 

No worries, just want to make sure future visitors stay on track Smiley Happy.

 

I'll browse over to your post when I get a chance.  Smiley Happy

 

Best,

 

Theo

 

 

Analytics Evangelist at MoreVisibility | Contact Me
Connect on LinkedIn