Regex Extractor equipped with dynamic regular expression in JMeter
Is there any way to set up a regex extractor with a regex that consists of dynamic variable (e.g, ${var}).
The rationale asking is because one section of my test plan is to get the User ID of a certain user account from the html response, so subsequently Jmeter will continue doing its business with that User ID as the reference. If I only worry about 开发者_开发知识库1 thread to the test plan, it will be as simple as below
<.*id=(/d+).*value="johndoe"
But I want the test plan to be flexible enough to handle multiple thread with each thread represents a unique user, so the regular expression will have to be something like below
<.*id=(/d+).*value="${USERNAME}"
One or two of advices on how to achieve this will be appreciated. If it's not achievable, an alternative way will also be good
Thanks
Greetings,
As a soon-to-be Jmeter lover, you'll find this happens often. You simply need to escape the special characters in your regex. The dollar sign has special meaning in PERL regular expressions, so we need to tell the regex to use a literal $:
<.*id=(/d+).*value="\${USERNAME}"
Also, the id section is a bit greedy. I would recommend:
<.*id=(/d+?) value="${USERNAME}"
I had a similar problem and simply escaping the $ character didn't work for me.
Instead I had to use the __V() function.
So in this example, the regular expression would be like below:
<.*id=(/d+).*value="${__V(${USERNAME})}"
I didn't have to escape the $ character. I'm using JMeter 2.9
In Apache JMeter 2.9, the correct expression the include a variable value ${MYVARIABLE} inside a Regular Expression is:
__V(${MYVARIABLE})
This should be placed in the desired place in the regex.
Works fine!!!
For me there is no need to escape anything (in Jmeter variables syntax). I'm using JMeter 2.9
Setting only variable (containing the whole regex, maybe dynamically generated) like ${regex} in the field "Regular Expression" also works.
This issue was irritating me too. The only solution that worked for me was adding a BeanShell Sampler with code of this sort:
String S = "blah-blah-blah...\\\d...${My variable}...blah-blah-blah";
vars.put("RegExp", S);
And Then in Regular Expression Extractor a used only this:
${RegExp}
NB Note that for some reason \d was needed to be screened with THREE backslashes...facepalm.jpg
For Jmeter 3.1 I had to use the ${__V(${MYVAR})} syntax as @spark and @carlos AG stated
The only way I did this was, First creating a String, concatenating the variables and the rest of the pattern and saving this into a variable (this in a PostProcessor). And putting it in the regular expression extractor.
I described very similar problem on jMeter 5.5-Snapshot 3a74a92 with working solution here: jMeter Regular Expression Extractor with use of variable in regexp
精彩评论