How do I extract a specific match from Regex Extractor - Jmeter - regex

So I got this response from the expression highlighted, but I need to get the last result the one in "Match [ 5 ] 1 "
I'm using this config, is this correct?
I've seen several examples online but they all use the same config, how can I get the one I'm asking for?
Thanks in advance
I've tried switching them and putting 5 in both fields, but I keep getting the Match [one][one] every time

If you have 5 matches you will have the special JMeter Variable form_build_id_matchNr with the value of 5 from where you can extract the last match so you can refer the last match using __V() function as:
${__V(form_build_id_${form_build_id_matchNr},)}
In this case you will need to set "Match No" in the Regular Expression Extractor to -1
More information: Here’s What to Do to Combine Multiple JMeter Variables
In general using regular expressions for parsing HTML is not the best idea, you might want to consider using CSS Selector Extractor and come up with the proper selector to match only the "interesting" value

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

Extracting Value In Between Quotes - Regular Expressions

I'm trying to extract a request ID for running load testing on J Meter that I need to use for the subsequent HTTP requests. I'm using the regular expression extractor to do this.
I've been trying for hours and hours to extract the value inside single quotations and have not had any success. The response looks similar to this.
RequestDateTime='2/12/2017 7:19:49 AM' RequestID='1234567' Client="14232" etc...
I want the exact numbers with no quotations around it. The value should be 1234567
I've tried using RequestID='(.*?)' but it gives the entire string whereas I just want the value inside.
Use regular expression RequestID='(\d+)
Template $1$
Match 1
Looking into "RegExp" Tester mode of the View Results Tree listener your regular expression itself is fine:
So my expectation is that your Regular Expression Extractor configuration is not correct, you should get expected value if use something like:
Reference Name: anything meaningful, i.e. RequestID
Regular Expression: RequestID='(.*?)'
Template: $1$
You should be able to refer the extracted value as ${RequestID} later on. Extracted JMeter Variable(s) can be visualised using Debug Sampler
See How to Debug your Apache JMeter Script article to learn more about JMeter tests troubleshooting techniques.
So the following regular expression should do the trick: '(\d*)'
Then Insert a Debug Sampler into your thread so you can see the reference name. The variable you are looking for will have the following name: referencename_g0
The _g0 represents the first group that was matched. If the expression matches other chars in your response, simply use the variable with the correct group number. (e.g _g1 or _g2, etc).
Hope this helps!

Regular expression to get value with duplicate data

Hi trying to extract my required string from given string. Given string looks like below.
1|a1|id11-name11,x|a2|id21-name21,y|a3|id31-name31~id32-name32,y4|a4|id41-name41~id42-name42~id43-name43
Expected output:
a1~name11|a2~name21|a3~name31|a3~name32|a4~name41|a4~name42|a4~name43
Regular Expression:
(^|,)[^|]{0,}\|([^|]{0,})\|(~){0,}[^-]{0,}-([^,~]{0,})
Extracting $2~$4| or \2~\4|
Regular Expression output:
a1~name11|a2~name21|a3~name31|
Is it possible to get a3~name32 along with a3~name31 using regular expression? Using multiple regular expression is also fine. Values in the third part after pipe symbol is not limited to 4 different values(id41-name41~id42-name42~id43-name43). This could be like id41-name41~id42-name42~id43-name43~id43-name43~id43-name43~id43-name43...
You have two choices first one is to split the string into many parts and get what you want.
Second one depends on the longest repeated part. In your case it is idxx-namexx.
If it is limited to a reasonable value you can repeat that part in you regex so you get all the parts. For instance for 2 you need to add the second part as follows:
([a-zA-Z]\d)\|(id\d+-(name\d+))(~?id\d+-(name\d+))?
______________-------1-------- _---------2--------_________
The groups will be
\1~\3 and
\1~\5
You can check it in Regex101 Site

regular expression multiple matches

For reference, this is the regex tester I am using:
http://www.rsyslog.com/regex/
How can I modify this regular expression:
[^;]+
to receive multiple sub-matches for the following test string:
;first;second;third;fourth;fifth and sixth;seventh;
I currently only receive one sub-match:
first
Basically I want each sub-match to consist of the content between ; characters, I am hoping for a sub-match list like this:
first
second
third
fourth
fifth and sixth
seventh
Following information given in the comments I discovered that the reason I can't get more than one sub-match is that I need to specify the global modifier - and I can't seem to figure out how to do that in the ryslog regex tester I am using.
However, this did lead me to solve my problem in a slightly different manner. I came up with this regular expression which still only gives one match, but the number near the end acts as the index for the desired match, so for example:
(?:;([^;]+)){5}
matches this from my test string in the question:
fifth and sixth
While this solution allows me to achieve what I wanted - though in a different manner - the true answer to my question is found in HamZa's comments. More specifically:
How can I modify the regular expression to receive multiple
sub-matches?
The answer is, you can't modify the regular expression itself in order to get multiple sub-matches. Setting the global modifier is required in order to do that.
Based on this information I have posted a new question on serverfault targeted specifically to the rsyslog regular expression system.

Google Analytics Regular Expressions

Kinda new to Rgeluar expressions and for the benefit of learning wanted to know how to do the following on one line:
page matching regular expression: .pdf/$
and page containing "somestring"
and page excluding "someotherstring"
I can obtain my desired output using the 3 rules above. My question is can I put all into one line using regular expression? So the first line would be something like:
page matching reg exp: .pdf/$ somestring+ (then regex for does not contain in GA) someotherstring
Is it possible to put all in a oner?
Lookahead will help you to match multiple independent things in one expression, and even allows to require non-matching. In your case:
/^(?=.*somestring)(?!.*someotherstring).*\.pdf$/