I am getting response from Jmeter like this:
<input type="hidden" id="queueItemId" name="queueItemId" value="3256"/>
I wanted to get value 3256 from this and store it in a variable. Then i can use this variable further use like ${variable}
.
For this i am using RegularExpressi开发者_如何学PythononExtractor
in scope of the Sampler.
Please give me the regular expression to extract this value.
Try something like:
encounterId=([0-9]+)
and use group 1 as the result.
Better than using regular expression to extract that value I would suggest using XPath Extraction like this:
//form[@name='MyForm']//input[@name='queueItemId']/@value
Where MyForm
is your form name, replace with whatever you have.
Actually the best awnser is from Ibu in the comment:
value=\"(\d+)\" and: value="([^"]+?)" will workfine too
So in jemter it will look like this:
reference name: value
Regex: (\s value=\"(\d+)\")
Regex: (\s value="([^"]+?)")
template : $2$
match no.:1
If you want only the value that have the reference name queueItemId you might want to modify the reg ex to this.
So from jmeter reg ex extractor you got :
reference name: queueItemId
Regex: (name="queueItemId" \s value="([^"]+?)")
Regex: (name="queueItemId" \s value=\"(\d+)\")
template : $2$
match no.:1
You should check the regex with jakarta oro because it's the reg ex engine that jmeter use.
Check out jakarta ORO here : http://jakarta.apache.org/oro/demo.html
ORO is a reg ex tool that behave almost exactly like jmeter.
Most of the time the the standart reg ex tool will work but it has happened to me sometime that the reg ex was fine in my tool but was not working in jmeter.
I later found out the ORO tool and was able to make it work in oro (and jmeter)
Another note: I think jmeter ignore space in your reg ex you have to add /s when you want to compare a space.
The most maintainable way in recent version of JMeter is to use CSS/JQuery Extractor:
The most performing one is to use new Boundary Extractor:
If you really want to use Regular_Expression_Extractor :
Here is the XPath query:-
//input[@type="hidden"][@id="queueItemId"][@name="queueItemId"]@value
or try this code regexId = '\d+';
The following regular expression will match the parameter and its value:
\bencounterId=(\d*)
The parentheses enable extraction of the value. Note the word boundary \b
which makes sure a parameter ending with encounterId
such as fooencounterId
is not matched.
var str = "<a href='/openmrs/module/moca/encounterViewer.form?encounterId=3537'></a>"
var regex = /<a.*?href='(.*?)'/;
var src = regex.exec(str)[1];
var numb = src.split("=")[1];
alert (numb);
精彩评论