Analytics
5.2K members online now
5.2K members online now
Ask questions about filter set-up and issues with using filters in Google Analytics reports
 
Guide Me
star_border
Reply

Using Regex Filter for a report

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

I want to filter for pages that start with /hotel/  but then I want to exclude pages that have another "/" after that point.   

For instance, I WANT to include these pages:

 

www.website.com/hotel/bestwestern

www.website.com/hotel/marriott

 

But I do NOT want pages like the following:

 

www.website.com/hotel/bestwestern/select-a-room

www.website.com/hotel/marriott/book

 

The problem is that the text after the 3rd slash can be almost anything.  Is there a regex expression that tells GA to stop at the 3rd slash or some other way to do this?

Spoiler
 
1 Expert replyverified_user

Re: Using Regex Filter for a report

[ Edited ]
Top Contributor
# 2
Top Contributor

Advanced regex lesson:  [quick oops fix]
The caret symbol ( ^ ) can be used to mean NOT if it is enclosed in square brackets. If it is used outside square brackets, it means the start of the term.
The dollar sign ( $ ) means end of the expression, and the plus sign ( + ) means one-or-more of the preceding character.
Regex is greedy, meaning if will match anything, anywhere in the term if it can.

Here is your expression:
^/hotel/[^/]+/[^/]+$

^/hotel/ starts with /hotel/
[^/]+ followed by one or more characters that are NOT /

/   followed by a slash

[^/]+ followed by one or more characters that are NOT /

 $ prevents a partial match followed by a /

Mike Sullivan, Google Analytics Top Contributor
Was my response helpful? If yes, please mark it as the ‘Best Answer.’ Learn how here.