Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 321
Daniel Avatar asked Dec 27 '22 23:12

Daniel


1 Answers

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}"
like image 152
BlackGaff Avatar answered Apr 09 '23 18:04

BlackGaff