Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Analytics Regex include and exclude string without negative lookahead

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.

like image 638
Chazz Avatar asked Feb 04 '26 18:02

Chazz


1 Answers

^(?:[^-]|-(?:[^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.

like image 80
ndnenkov Avatar answered Feb 06 '26 07:02

ndnenkov