1

I'm relatively new to regex and in order to set up a goal in Google Analytics, I'd like to use a regular expression to match a URL containing both "thank-you" and "purchaseisFree=False" but exclude two specific rate plans that are represented in the URL as "productRatePlanID=5197e" and "productRatePlanID=c1760".

Here is a full URL example: https://www.examplepage.com/thank-you?productRatePlanId=5197e&purchaseIsFree=False&grossTotal=99.95&netTotal=99.95&couponCode=&invoiceNumber=INV00000589

I tried using this post as a model and created this regex:

\bthank-you\b.+\purchaseIsFree=False\b(?:$|=[^c1760]|[^5197e])

However, I'm not getting the desired results. Thanks in advance for any suggestions.

Community
  • 1
  • 1
dhc
  • 13
  • 4

1 Answers1

1

I think the below mentioned regex should solve your problem. It uses the positive|negative look ahead facility. We can sit at the beginning of http[s] and check all the three condition and then engulp the whole tree

(https?:\/\/)(?=.*?productRatePlanId=(?!5197e&)(?!c1760&))(?=.*?thank-you)(?=.*?purchaseisFree=False).*

Note:- I have used & after the productRatePlanId values just to ensure it doesnt ignore other values as 5197f, 5198d and all other sorts of values.

Gaurav
  • 104
  • 1
  • 7
  • Thumbs up!! Except small typo - `purchaseisFree=False` should have a capital `I`. :) – Bryan Elliott Jan 05 '14 at 23:07
  • 1
    I got this to work on RegExr but Google Analytics doesn't support look ahead expressions. Is there a modification to this regex that doesn't use look ahead expressions? – dhc Jan 05 '14 at 23:55
  • I don't think we can do much without look ahead, mostly because of two reason. a) you haven't specified and order in which the above three expression may come in URL and secondly its difficult to do group negation without look ahead. If you are in real need than capture the value and then do string comparison for productratePlanId. [Note :- In the sample regex which you have given in Question also uses look ahead) – Gaurav Jan 06 '14 at 03:10
  • Gaurav, even though it was my understanding that look ahead expressions weren't recognized, the regex you provided is working as expected. One change I made was to remove the (https?:\/\/) as Google Analytics works off matches after the root URL. Thanks! – dhc Jan 08 '14 at 00:32