Reputation: 89
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
Upvotes: 0
Views: 3280
Reputation: 168082
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:
In both cases you can use HTTP Cookie Manager
CookieManager.save.cookies
property set to true
you should be able to access the cookie value as ${COOKIE_JSESSIONID}
Upvotes: 0
Reputation: 357
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
Upvotes: 1
Reputation: 1899
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
Upvotes: 1