Haris Hashim
Haris Hashim

Reputation: 33

JMeter Regular Expression Extractor to extract custom header "access-token"

I have bellow response header that is giving me the problem when extracted using Regular Expression Extractor. To keep to story short, after troubleshooting I come up with a solution that works but is not perfect.

The Headers

Response headers:
HTTP/1.1 200 OK
Vary: Origin, Accept-Encoding
Access-Control-Allow-Credentials: true
X-XSS-Protection: 1; mode=block
X-Frame-Options: DENY
X-Download-Options: noopen
X-Content-Type-Options: nosniff
access-token: GAbnLmcDzT4j5INPkSGwdbQzZIIFIaJoy4wBnmNUF4NEgGB11IfzTAMdqXyxIhAZ
Access-Control-Expose-Headers: access-token
Content-Type: application/json; charset=utf-8

The Solution

Regular Expression : access-token: (.+?)\n

Template : $1$

Refer to below picture on why I think the solution is wrong. Extracted token is represented by multiple variable as result_token, result_token_g, result_token_g0, result_token_g1:

enter image description here

The Question

What is the correct Regular expression and template to get only the token.

TIA!

UPDATE:

Bellow excerpt from Regular Expression Extractor Doc actually help me better understand this question.

If the match number is set to a negative number, then all the possible matches in the sampler data are processed. The variables are set as follows:

refName_matchNr - the number of matches found; could be 0

refName_n, where n = 1,2,3 etc - the strings as generated by the template

refName_n_gm, where m=0,1,2 - the groups for match n

refName - always set to the actual template value if a match is found, otherwise, the default value.

Upvotes: 1

Views: 2145

Answers (2)

Richard RP
Richard RP

Reputation: 525

It seems to me, that you are getting it right; result-token_g1 contains the intended capture, and it is replicated via your template to result-token.

Don't worry about result-token_g0; it's supposed to show the complete match: capture AND context.

Upvotes: 0

Masud Jahan
Masud Jahan

Reputation: 2978

Use this:

Regular Expression : access-token: (.\w*)

Template: $1$

Match No: 1

DefaultValue:  Not found

Upvotes: 0

Related Questions