0

I had planned to use Jmeter Regex Extractor to get a Session ID in HTTP Response Header. This is the example of the HTTP Header :

HTTP/1.1 200 OK
x-powered-by: yoke
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: POST,GET,DELETE,PUT
Access-Control-Allow-Headers: X-Requested-With,jsessionid,Origin,Accept,Content-Type
Access-Control-Expose-Headers: Content-Size,Message,Total-Pages,Total-Count,Current-Page,jsessionid,Origin,Total-Outstanding,Content-Range
content-type: application/json
jsessionid: 10838d69-f9ac-4c70-b1f7-9447a7a6a463
Content-Length: 106

All I need to get is :

10838d69-f9ac-4c70-b1f7-9447a7a6a463

I use this REGEX :

jsessionid: [^\n]+

But I get :

jsessionid: 10838d69-f9ac-4c70-b1f7-9447a7a6a463

Can you help me with it? Thank you

Best Regards, Stefio

3 Answers 3

1

Use the regex expression

jsessionid: ([^\n]+)

and Template

$1$

Your issue has to do with regex grouping. Group 0 is the entire match, which is the default of Jmeter Regex Extractor. Group 1 is what was matched by the regex inside the first set of parenthesis. Template $1$ says to use the contents of group 1 as your result. Regex grouping can get much more complicated, so read tutorials if you want to grab multiple values from a regex expression. Jmeter Regex Extractor user manual

Sign up to request clarification or add additional context in comments.

1 Comment

the regular expression above works on my jmeter. Thank you chris.
1

Look into lookaround for regex, for you particular case it'd be lookbehind regex. This outght to work, untested though:

(?<=jsessionid:\s).+

The (?<=jsessionid:\s) part means literraly match jsessionid: but don't include it in results

2 Comments

The above one also selects the new line character me. So tried this (?<=jsessionid:\s)[^\s]+
this is works when I need to search the HTTP Header value (with notepad++ for example). Unfortunately, Regex Extractor Jmeter cannot find the specific response header value.
0

JSESSIONID is basically a cookie so I don't think you need to extract it with regex.

I can think of 2 scenarios why you might need it:

  1. You need to pass it with the next request as a header
  2. You need its value for something else

In both cases you can use HTTP Cookie Manager

  • For the 1st option: it handles cookies automatically
  • For the 2nd option: given CookieManager.save.cookies property set to true you should be able to access the cookie value as ${COOKIE_JSESSIONID}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.