3

I'm trying to set up a Goal in Google Analytics using regular expressions to match urls that should contain the string "_thanks" but should not match urls that contain "-cl-" or "-wf-" or "-wl-".

This would be easier to do if Google Analytics would support negative lookahead, but unfortunately it doesn't.

For example the Goal should match:

/ba-ck-wp-example-of-a-page_thanks.html?ad=1073
/ba-default-page_thanks.html
/ba-nt-visit-some-page_thanks.html?ad=1731

But shouldn't match:

/ba-cl-a-free-quote_thanks.html
/ba-wf-information-report_thanks.html
/ba-wl-information-otherreport-example_thanks.html

Any help would be much appreciated.

Chazz
  • 305
  • 3
  • 12
  • 1
    I guess you need to create separate Exclude filters and move them to "Available Views". – Wiktor Stribiżew Jan 05 '16 at 12:41
  • Yes that would be a possibilty but working with different views is not what I was looking for. Urls that match "-cl-" or "-wf-" or "-wl-" are seperate goals and I want to see all goals together in one view. – Chazz Jan 05 '16 at 14:01

1 Answers1

1
^(?:[^-]|-(?:[^cw].?|c[^l]|w[^fl])-|-.{2}[^-])*_thanks

As you can see, the complexity increases as the length of the words you don't want to match (in this case 4 characters) grows.

ndnenkov
  • 35,425
  • 9
  • 72
  • 104
  • 1
    Thanks this works! Quite complex indeed, but probably a necessary workaround without negative lookahead. – Chazz Jan 05 '16 at 13:58
  • Given that it's similar and probably something simple that I'm missing in my regex, I wonder if you know how to solve this? https://stackoverflow.com/q/58259878/470749 Thanks. – Ryan Oct 06 '19 at 20:55