0

I'm trying to use GA to filter out certain URL pages. I need to distinguish between pages like this:

www.example.com/hotel/hotelfoofoo 

and this:

www.example.com/hotel/hotelfoofoo/various-options-go-here?lots-of-other-stuff-follows

I'm new to regex, so I know very little, but am basically trying to capture URL pages that begin with /hotel/ but do not include any other forward slashes. Is there a way to write that code?

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
Scarlet
  • 11
  • 1
  • 3
  • can anyone help??? in desperate need. thank you – Scarlet Dec 08 '15 at 00:32
  • Can you provide more examples of what you want to match and what you don't? – Dmitry Dec 08 '15 at 00:34
  • I want to match visits to the hotel page overview, which for every hotel on the site matches /hotel/hotelname. But I don't want to include pages where the visitor went on to "select a room", or "check available dates", etc. Whenever the user does those things, it still begins with /hotel/hotelname but then goes on to include another "/" and various text afterwards. – Scarlet Dec 08 '15 at 00:54
  • Use negative lookahead check like in this question like here: http://stackoverflow.com/questions/1749437/regular-expression-negative-lookahead . Simple example: hotelfoofoo(?!/). Not I want be able to help with regexp until you provide 3 different examples of what you want to match and 3 examples of what you don'r – Dmitry Dec 08 '15 at 00:58
  • Just update question with examples. – Dmitry Dec 08 '15 at 01:17
  • Okay, I DO want to include these 3: /hotel/Hotel-Palace-Berlin-Berlin-Germany /hotel/The-Ritz-London-London-England /hotel/Halekulani-Honolulu-HI I do NOT want to include these 3: /hotel/Hotel-Palace-Berlin-Berlin-Germany/select-room?cvosrc=partners.trivago.view_deals_lhwde /hotel/The-Ritz-London-London-England/book?cvosrc=partners.trivago.view_deals_lhwuk /hotel/Halekulani-Honolulu-HI?pid=APACHalekulani&cvosrc=social_media.facebook.apachalekulani_post – Scarlet Dec 08 '15 at 01:30

1 Answers1

0

Two possible solutions:

1) Assuming only alpha numeric + '-' signs allowed in the name of hotel:

/hotel/([-\w]+)(?![-\/\w])

Note: hotel name would be caught in first group. Idea here - is to capture all digits/letters/underscor/- symbols which are not followed by slash.

2) Assuming white space symbol required to designate url end:

/hotel/([^\s/]+)(?=\s)

Note: depending on your regexp language some of character should be escaped. For js all "/" should be escaped e.g.: "/"

Dmitry
  • 1,263
  • 11
  • 15