Dean
Dean

Reputation: 1236

Regular expression to check path of url as well as specific parameters

I have url's like the following:

/home/lead/statusupdate.php?callback=jQuery211010657244874164462_1455536082020&ref=e13ec8e3-99a8-411c-be50-7e57991d7acb&status=5&_=1455536082021

I would like a regular expression to use in my Google analytic goal that checks to see that the request uri is /home/lead/statusupdate.php and has ref and status parameter present regardless of what order these parameters are passed and regardless of if there are extra parameters because I really just care about the 2. I have looked at these examples

How to say in RegExp "contain this too"? and Regular Expressions: Is there an AND operator? but I can't seem to adapt the examples given there to work.

Im using this online tool to test http://www.regexr.com/ (perhaps the tool is the buggy one? I'l try in javascript in the mean time)

Upvotes: 0

Views: 452

Answers (3)

Alexander Derck
Alexander Derck

Reputation: 14488

Not really elegant but this works:

\/home\/lead\/statusupdate\.php(.*(ref|status)){2}

Looks for /home/lad/statusupdate.php followed by 2x any character followed by ref or status. Admittedly this would be a match for an url with 2x ref or status though.

Demo

Upvotes: 0

Mathieu Gemard
Mathieu Gemard

Reputation: 571

You can try:

\/home\/lead\/statusupdate\.php\?(ref=|.*(&ref=)).*(&status=)

if the order does not matter, then add the oppostite

\/home\/lead\/statusupdate\.php\?(status=|.*(&status=)).*(&ref=)

all put together

\/home\/lead\/statusupdate\.php\?(((ref=|.*(&ref=)).*(&status=))|((status=|.*(&status=)).*(&ref=)))

Upvotes: 1

Ankit Shubham
Ankit Shubham

Reputation: 3599

try:

(/home/lead/statusupdate.php?A)|(/home/lead/statusupdate.php?B)|(/home/lead/statusupdate.php?C)|(/home/lead/statusupdate.php?D)|(/home/lead/statusupdate.php?E)|(/home/lead/statusupdate.php?F)

Note that here A,B,C,D,E,F are notations for six different permutations for 'callback' string, 'ref' string, 'status' string and '_' string.

Upvotes: 0

Related Questions