1
votes

I am using the Regular Expression Extractor to extract an authentication code which I need to use in the following JMeter Sampler in my test. This code is saved in the response Header as Authentication: djdjf...## (a bunch of letters and numbers followed by ##).

In the Regular Expression Extractor "Field to check" I selected the "Response Headers" radio button.

Then I entered:

Reference Name: Auth

Regular Expression: \A\w*==\z

Template: $1$

Match No. (0 for random): 1

Default Value: NOT FOUND

Where do the results from the Regular Expression Extractor execution get saved?

I was hoping the results would get saved in a User Defined Variable, defined as Auth in my Test Plan's User Defined Variable section, but if I enter Auth in the "Reference Name" of the Regular Expression Extractor, and run JMeter, Auth never gets populated.

3
You select the template as $1$, but do not use capturing groups inside the regex. Try \A(\w*==)\z if you want the whole value to be captured. - Wiktor Stribiżew

3 Answers

1
votes

You do not need to create a separate User Defined variable for this. The name you give in the Reference name field will be used as a variable to store the match found using the regular expression pattern.

So, To access the value, just use ${Auth}. It should give the result from regular expression or NOT FOUND

1
votes

Very Easy and Simple way is:-

After Regular Expression Extractor put Debug Post Processor.

1- Right click on your request where you already created Regular Exp -> Add -> Post processor -> Debug PostProcessor

2- In Debug PostProcessor at the place of name give the variable name which you taken for extract, like ${Name}

3- Now in Listener part after test run you will get the Exact Value which is passed in regular expression.

0
votes

JMeter uses Perl5-style regular expressions via Jakarta ORO.

You can use ORO demonstration applet or View Results Tree listener to debug your regular expression

I would suggest to substitute your "Regular Expression" with something as simple as Authentication: (.*) keeping other fields as they are.

Once extracted you should be able to refer extracted header as ${Auth} or ${__V(Auth)} where required.

Declaring "Auth" variable via User Defined Variables is not mandatory, it will be created in the Regular Expression Extractor.