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

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)

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=)))

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.

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

Related

regexing url parameters IIS

I have reviewed a couple questions on regexing url parameters, but none of which seem to specifically address my issue. I have been trying to work out the correct regex pattern in www.regex101.com and I haven't found any successs. I have a url that has parameters which are separated by /'s. I am able to regex one parameter at a time, but I would ideally like to develop a pattern that can extract all of the parameters. So far this is what I have:
\/([a-zA-z]+)\/([a-zA-z]+)\/([a-zA-z-]+)\/
The url that I am trying to modify is:
www.mydomain.com/firstparameter/secondparameter/hyphenated-url-parameter/
The above pattern works for this example, but I need it to also work for these two examples:
www.mydomain.com/firstparameter/secondparameter/
www.mydomain.com/firstparameter/
Is it even possible to write one singular regex that can extract the parameters from each example above?
Try Regex: \/([a-zA-z]+)\/(?:(?:([a-zA-z]+)\/)?([a-zA-z-]+)\/)?
Details:
? Quantifier — Matches between zero and one times, as many times as possible
Demo
The assumption here is that, there is at least one parameter and max 3 parameters.
This should work for any number of parameters:
\/([\w|-]+)
Example

APIGEE - Regular Expression Not Working in Condition

I am trying to use a condition to catch the case in which the query string of a request contains two or more parameters from a specific list. In such a case I wish to raise an error.
Of course, I can use many "and" and "or" clauses, but that will get very messy very quickly as the size of the list of parameters increases. So instead, I opted to use a regex to test for this.
As an example, if the list of parameters is [Bird,Dog,Horse], then any request who has two or more of these parameters in its query string should be matched.
The regular expression I am using is:
/(.(Bird|Dog|Horse).){2}
I tested in various regex testers and it works.
However, when I put the condition:
request.querystring Matches "/(.(Bird|Dog|Horse).){2}"
I never get a match.
Am I missing some specific APIGEE regex rules? Maybe the "{2}" is not supported in APIGEE? Thank you very much!!
Adam
The problem was I used "Matches" instead of "JavaRegex".
I tried "JavaRegex" before, but it also didn't work - the second problem was that I have the "/" at the beginning, which is not needed if you use "JavaRegex".
https://community.apigee.com/questions/65080/regular-expression-not-working-in-condition.html?childToView=65113#answer-65113

How to parameterize a regular expression in jmeter

I have a variable
announcementName= test
I am trying to use regEx Extractor to match an expression in jmeter.
I am able to match data with the below expression.
{"id":(.*?),"announcementName":"test",
However I am unable to pass test as a variable to the same expression
{"id":(.*?),"announcementName":"${announcementName}",
I am unable to match anything with the above regEx matching.
Can someone please let me know on how to pass parameters to RegEx Extractor in Jmeter.
As per my experience, if you try this approach in listener to verify whether correlation is working or not than obviously it's not going to work.
But if you are passing this directly in reg ex extractor and trigger the script then it should work provided the variable does not contain any special character like (.,?) etc. (As you mentioned test as value so seems you took an example to display here but actual value is something else, so please check actual value once again to confirm it's a simple string without any special characters)
You can check with __V() function.
i.e.
{"id":(.*?),"announcementName":"${__V(${announcementName})}",

need a regular expression that copes with this URL:

I have a URL from google circles that doesn't get validated by normal regular expressions. for instance, asp.net provides a standard regular expression to cope with URLS, which is:
"http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?"
But when you get a google circles URL:
https://plus.google.com/photos/114197249914471021468/albums/5845982797151575009/5845982803176407170?authkey=CKfNzLrhmenraA#photos/114197249914471021468/albums/5845982797151575009/5845982803176407170?authkey=CKfNzLrhmenraA
it can't cope.
I thought of appending to the end the following expression: (\?.+)?
which basically means the URL can have a question mark after it and then any number of characters of any type, but that doesn't work.
The whole expression would be:
"[Hh][Tt][Tt][Pp]([Ss])?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*(\?.+)?)?"
For some reason, that doesn't work with complicated URLs either.
Help is appreciated.
I added the anchors ^ and $ for the purposes of this test, escaped the / because the following is a javascript regex literal, changed the &, which had no business being there, to &;, removed the space and added # to the third character set, and it seems to work okay:
/^http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w.\/?%&;#=-]*)?$/.test(
'https://plus.google.com/photos/114197249914471021468/albums/5845982797151575009/5845982803176407170?authkey=CKfNzLrhmenraA#photos/114197249914471021468/albums/5845982797151575009/5845982803176407170?authkey=CKfNzLrhmenraA' )
// true
I also moved the - to the end in the third character set, as it should be at the start or end of the set if not specifying a range.
Disclaimer: I do not propose this as good way of validating urls in general, it is just an edited version of the original regex which now works in this specific case.

Regex with URLs - syntax

We're using a proprietary tracking system that requires the use of regular expressions to load third party scripts on the URLs we specify.
I wanted to check the syntax of the regex we're using to see if it looks right.
To match the following URL
/products/18/indoor-posters
We are using this rule:
.*\/products\/18\/indoor-posters.*
Does this look right? Also, if there was a query parameter on the URL, would it still work? e.g.
/products/18/indoor-posters?someParam=someValue
There's another URL to match:
/products
The rule for this is:
.*\/products
Would this match correctly?
Well, "right" is a relative term. Usually, .* is not a good idea because it matches anything, even nothing. So while these regexes will all match your example strings, they'll also match much more. The question is: What are you using the regexes for?
If you only want to check whether those substrings are present anywhere in the string, then they are fine (but then you don't need regex anyway, just check for substrings).
If you want to somehow check whether it's a valid URL, then no, the regexes are not fine because they'd also match foo-bar!$%(§$§$/products/18/indoor-postersssssss)(/$%/§($/.
If you can be sure that you'll always get a correct URL as your input and just want to check whether they match you pattern, then I'd suggest
^.*\/products$
to match any URL that ends in /products, and
^.*\/products\/18\/indoor-posters(?:\?[\w-]+=[\w-]+)?$
to match a URL that ends in /products/18/indoor-posters with an optional ?name=value bit at the end, assuming only alphanumeric characters are legal for name and value.