How to correlate value for new line value - jmeter

I am trying to correlate below values but not able to do it.
I have searched below regex in regex tester but it is not working.
Value:1:
this.setRequestHeader("tempSpecId", "737896904057736821");
tried regex:this.setRequestHeader(\s+"tempSpecId",\s+"([^"]+)"\s*)
value:2:
var tririgaSecurity = new TririgaSecurity("NDBkZTEyYzQxMDVl","HzrbV1mi-KKloFirhlE91LHiTV-s4M_A");
Here both the values are changing and not able to find it in regex tester with below:
"tririgasecuritytokeninput", "([a-zA-Z0-9]+)
Please let me know how to handle these values.
you're help will be appreciated.

When you are using regular expressions with round braces, they become a pattern group. A simpler solution would be to use this regex for value 1
(\s*"tempSpecId",\s*")(\d*)
and the template would be $2$ along with the match No set to 1
For value 2, use the following regular expression
TririgaSecurity[(]"([\w]*)","(.*)"
for the first value which is 'NDBkZTEyYzQxMDVl', can be obtained from the 1st pattern group i.e by using the template $1$ and the match No set to 1
the second value which is 'HzrbV1mi-KKloFirhlE91LHiTV-s4M_A' can be obtained from the second pattern group of the regex result i.e. the template $2$ and the match No set to 1
Here is the response in the Debug Postprocessor, for the same regular expressions and the pattern groups

Related

How to get the required value from the existing value when there is no suffix?

I'm trying to use regular expression extractor concept in Jmeter. By using regEx concept I'm able to get the required token id's. And for all I'm using regEx as (.*?). So this is working fine when we have constant prefix and suffix text/values.
But in this case, there is no suffix,
Ex: Key is = #bluerelay.com/a43a816dcdd14873bd5757b3a3709d5c,
ClickHereForImageForm
I want to take the key ID into a variable with using RegEx. I have tried to get it with (.*?) but it didn't work, it returns the full value, not the required part. It'd be excellent if you could give any suggestion.
The source value is:
https://navitus-internal-app.bluerelay.com/#/token/systemadministrator#bluerelay.com/a43a816dcdd14873bd5757b3a3709d5c
The expected result is to extract a43a816dcdd14873bd5757b3a3709d5c from the above URL and put it into a variable.
You can use regex to get last text after / sign
(.*)\/(\w+)
See demo

Regular expression to get value in between parentheses

I am trying to write a regular expression to get the value in between parentheses. I expect a value without parentheses. For example, given:
value = "John sinu.s(14)"
I expected to get 14.
I tried the following:
value[/\(.*?\)/]
but it gives the result (14). Please help me.
You may do that using
value[/\((.*?)\)/, 1]
or
value[/\(([^()]*)\)/, 1]
Use a capturing group and a second argument to extract just the group value.
Note that \((.*?)\) will also match a substring that contains ( char in it, and the second option will only match a substring between parentheses that does not contain ( nor ) since [^()] is a negated character class that matches any char but ( and ).
See the Ruby demo online.
From the Ruby docs:
str[regexp, capture] → new_str or nil
If a Regexp is supplied, the matching portion of the string is returned. If a capture follows the regular expression, which may be a capture group index or name, follows the regular expression that component of the MatchData is returned instead.
In case you need to extract multiple occurrences, use String#scan:
value = "John sinu.s(14) and Jack(156)"
puts value.scan(/\(([^()]*)\)/)
# => [ 14, 156 ]
See another Ruby demo.
Another option is to use non-capturing look arounds like this
value[/(?<=\().*(?=\))/]
(?<=\() - positive look behind make sure there is ( but don't capture it
(?=\)) - positive look ahead make sure the regex ends with ) but don't capture it
You can use
/(?<=\\()[^\\)]+/g
which selects string inside brackets without brackets
Only thing you need is "positive lookahead" feature
Follow this link for more info about positive lookahead in special groups.
I don't know if it is supported in ruby
Try using this regular expression
/\((.*?)\)/
\( will match your opening parenthesis in the string
(.*?) creates a capturing group
\) will match your closing parenthesis
Do you wish to extract the string between the parentheses or do that using a regular expression? You specify the latter in the question but it's conceivable your question is really the former and you are assuming that a regular expression must be used.
If you just want the value, without any restriction on the method used to obtain it, you could do that quite simply using String#index and String#rindex.
s = "John sinu.s(14)"
s[s.index('(')+1 .. s.rindex(')')-1]
#=> "14"

How to add regular expression extractor for more than 1 viewstate in jmeter for asp.net page

I have 10 different __viewstate values in jmeter script. one is for login and others are for post methods. how can i use regular expression extractor to parameterize the viewstate for performance testing.
As per regular expression extractor documentation:
If the match number is set to a negative number, then all the possible matches in the sampler data are processed. The variables are set as follows:
refName_matchNr - the number of matches found; could be 0
refName_n, where n = 1,2,3 etc - the strings as generated by the template
refName_n_gm, where m=0,1,2 - the groups for match n
refName - always set to the default value
Set match number -1 for one expression to return all matches from the response.
As RaGe mentioned in the comment, you can just use 1 Regular Expression Extractor to find all the matches for the given pattern.
Regular Expression Extractor - Example
MatchNo :
0 for random
1 for first match
2 for second match and so on.
-1 for all matches
When you enter -1 & get all matches, to access the first match, use TheVariableName_1

Copy the Value upto specific range using regular expression extractor in JMeter

I want to capture the certain range of values using regular expression extractor in jmeter. Like "sessionid": "15F36C8A123D4483935062DDE73280CB\x2D0\x3A1",
In the above value I need to exclude the \x2D0\x3A1 and capture the value.
You will have to define two regular expression, assuming that x2 and x3 are good enough token to separate these two fields.
1st : x2([0-9A-Fa-f]+)
2nd : x3([0-9A-Fa-f]+)
Update: I misunderstood the original post and gave the solution to exclude the first part of the session id and extract the two values which seems like some range.

Ruby String: how to match a Regexp from a defined position

I want to match a regexp from a ruby string only from a defined position. Matches before that position do not interest me. Moreover, I'd like \A to match this position.
I found this solution:
code[index..-1][/\A[a-z_][a-zA-Z0-9_]*/]
This match the regexp at position index in the string code. If the match is not exactly at position index, it return nil.
Is there a more elegant way to do this (I want to avoid to create the temporary string with the first slice)?
Thanks
You could use ^.{#{index}} inside the regular expression. Don't know if that's what you want, because I don't understand your question completely. Can you maybe add an example with the tested String? And have you heard of Rubular? Great way to test your regular expressions.
This is how you could do it if I understand your question correctly:
code.match(/^.{#{index}}your_regex_here/)
The index variable will be put inside your regular expression. When index = 4, it will check if there's 4 characters from the beginning. Then it will check your own regular expression and only return true if yours is valid as well. I hope it helps. Good luck.
EDIT
And if you want to get the matched value for your regular expression:
code.scan(/^.{#{index}}([a-z_][a-zA-Z0-9_]*)/).join
It puts the matched result (inside the brackets) in an Array and joins it into a String.

Resources