wrphillip
wrphillip

Reputation: 1

How do I escape a certain word in a URL with Google Analytics regex?

I'm trying to set up a regex to escape a certain word in a URL with Google Analytics goals.

Currently the URL path is:

  1. /pricing/mls

  2. /pricing/armls

  3. /pricing/armls/bundle/5

Step 1 is static, and will always stay that way but step 2 has over 80 different possibilities. I wanted to set up a Regex that will specifically escape "mls". Using the (.*) would also grab the mls page which I'm trying to escape. Currently my regex looks like this:

^\/pricing\/mls$

^\/pricing\/(.*) this is where I'm trying to escape the mls portion ^\/pricing\/(.*)\/bundle\/(5|6|7)

I tried (?!mls) but Google Analytics doesn't support negative look aheads. Any help would be much appreciated, thanks everyone!

Upvotes: 0

Views: 77

Answers (1)

wp78de
wp78de

Reputation: 18950

Without a negative lookaround is going to get messy.

The only clean way I see is to use an optimized whitelist of alternations like this:

^\/pricing\/((?:[ac]r|t)mls|mlspin|realcomp)\/bundle\/(5|6|7)

Demo

Tip: I used myregextester.com to get the inner part optimized (just enter your pattern, tick the OPTIMIZE checkbox, and submit).

[*]: Side note: Google Analytics doesn't support single and multiline modes since URLs can't contain newlines. So, there should be never any need for ^ and $ to match anywhere but the beginning and end of the whole string.

Upvotes: 1

Related Questions