Let us say we have a login page and a authenticate page as http requests in a thread group. Lets say we want to pass some info we get in response of login page to the request of authenticate page.So instead of hard coding the values of username and password in request of authenticate page we want to read it using reg expression.
For that we add a post processor to the login page called Reg Expression Extractor.
In the req expression extractor we do the following
Name of the created variable -->Userdata1
Then in Reg Expression we copy paste the line from login response body
Enter <em>(.+?)</em> for the username and <em>(.+?)</em> for the password
But instead of actual username and password we type .+? which means anything that comes at this place as these values might change in future.
Then in template we write $1$ which means capture the first value in the brackets()
So we are saving these values in the variable we defined that is Userdata.
In match random type 1 and in default value give any value i.e if no value is found use this value.
Now how do we know how are these values saved.
We add a results tree to our thread and a debug sampler to our thread as well. We run the test and go to results tree and click the debug sampler and in response data and response body we see username is saved as
Userdata_g1
and password is saved as Userdata_g2
We go to our authenticate step and instead of hard coding the values type this
${Userdata_g1}
and ${Userdata_g2}
in place of values of username and password