How to check for NOT this number in SoapUI Assertion - regex

I am writing some Soap UI tests and am trying to figure out if there is a way with regular expressions to check for a string that does not contain a specific number. In this one case I want to make sure that when I get a response that my recordCount field DOES NOT contain 0. I thought this might be easier but while I can see a way to check for a set of numbers the regular expression for not this doesn't seem to work. Probably only detects characters and not numbers.
My XML contains this:
<recordCount>0</recordCount>
What I want is something like
recordCount>[^0]
so I can make sure recordCount shows up in the response, but also check that at least the first number it finds is not a 0. Is there any way to do this?
Edit: Using SiKing's answer I just used the NotContains to look for recordCount>0 ; this covers the couple of cases where I don't look for specific data only how many records are returned and in those cases it just needs to be more than 0

Why does it have to be regular expression?
You can use either of the following XPath assertions, for all of which the expected result is false:
//*:recordCount = 0
exists(//*:recordCount[text()='0'])

Using regular expressions you could do something like that:
(?s).*<recordCount>[^0]</recordCount>(?s).*
When using regular expressions in an assertion in SoapUI, you have to take whitespace and line breaks into account. In the example code (?s).* works as a wildcard that includes all whitespace and line breaks.

Related

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})}",

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

RegEx SQL, issue escaping quotes

I am trying to use PSQL, specifically AWS Redshift to parse a line. Sample data follows
{"c.1.mcc":"250","appId":"sx-calllog","b.level":59,"c.1.mnc":"01"}
{"appId":"sx-voice-call","b.level":76,"foreground":9}
I am trying the following regex in order to to extract the appId field, but my query is returning empty fields.
'appId\":\"[\w*]\",'
Query
SELECT app_params,
regexp_substr(app_params, 'appId\":\"[\w*]\",')
FROM sample;
You can do that as follows:
(\"appId\":\"[^"]*\")(?:,)
Demo: http://regex101.com/r/xP0hW3
The first extracted group is what you want.
Your regex was not matching because \w does not match -
Adding this here despite this being an old question since it may help someone viewing this down the road...
If your lines of data are valid json, you can use Redshift's JSON_EXTRACT_PATH_TEXT function to extract the value a given key. Emphasis on the json being valid, as it will fail if even one line cannot be parsed and Redshift will throw a JSON parsing error.
Example using given data:
select json_extract_path_text('{"c.1.mcc":"250","appId":"sx-calllog","b.level":59,"c.1.mnc":"01"}','appId');
returns sx-calllog
This is especially useful since Redshift does not support lookahead/lookbehind (it is POSIX regex) & extract groups.
You can try using some lookahead and look behinds to isolate just the text inside the quotes for the appid. (?<=appId\":\")(?=.*\",)[^\"]*. I tested this out a bit using your examples you provided here.
To explain the regex a bit more: (?<=appId\":\")(?=.*\",)[^\"]*
(?<=appId\":\"): positive look behind for appid":". Since you don't want the appid text itself being returned (just the value), you can preface the regex with a look behind to say "find me the following regex, but only when it is following the look behind text.
(?=.*\",): positive look ahead for the ending ",. You don't want quotes to be returned in your match, but as with number 1 you want your regex to be bounded a bit and a look ahead does that.
[^\"]*: The actual matching portion. You want to find the string of chars that are NOT ". This will match the entire value and stop matching right before the closing ".
EDIT: Changed the 3rd step a little bit, removed the , from that last piece, it is not needed and would break the match if the value were to actually contain a ,.

Regex assistance: include/exclude

Hello I am trying to figure out this RegEx expression. I have a URL that can have different querystring parameter at different location.
test.aspx?foo=bar&abc=123
test.aspx?abc=123&foo=bar
test.aspx?foo=bar&abc=123#T1
test.aspx?abc=123&foo=bar#T2
I am trying to only find the one without the #Tnumber
Here what I have so far.
test.aspx\?(?!\#T[0-9])
However it still select all of them, is there a way to have a string constant and scan it down the line?
Juniorflip
If #Tnum is always at the end, you just need to do a bit of anchoring. For example, like this:
test.aspx\?.*(?!\#T[0-9])...$
But that's very fragile as it depends on the bad URLs always ending in a very particular form and good URLs always having enough characters to soak up that end matching. A negative lookbehind assertion is somewhat better, but still fragile and less commonly supported:
test.aspx\?.*(?<!\#T[0-9])$
It's better to write a regular expression that matches what you don't want and to just invert the logic of what to do when you get a match (i.e., "if it matches throw it away", instead of "if it matches use it"). But really it's much better to delegate the parsing of the URLs to a specialized library and then just do a simpler check against the fragment identifier as a logical component instead of as a horrible RE hack.