Search code examples
testingloadjmeter

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


Solution

  • 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}"