mariansdj
mariansdj

Reputation: 33

jMeter - Extract Value from Variable

I am using jMeter to perform a stress test of a website. I need to pass a variable's value to the next Request.

The value can be seen as follows in the response body:

var _data = {};
_data["_as_csrf_token"] = "64da5d341c253c2a181796d2524e57c6502d906b";
jQuery.ajaxSetup({ data: _data, type: "POST" });

How should I use the Regular Expression Extractor to get this value?

Upvotes: 3

Views: 1585

Answers (3)

Abhishek Puri
Abhishek Puri

Reputation: 373

Please use the following string to extract the data using ReEx Extractor.

_data\[\"_as_csrf_token\"\] \= \"(.+?)\"\;

As shown in the screenshot below Regular Expression Extractor Example In case you are worried about the data to be extracted. I would suggest using https://regexr.com/ The reason why i prefer this site is because it helps you with the cheatsheet as well.

Second question, why (.+?) why not anything else? The reason is that it matches every kind of text within the pattern. No need to worry about the special characters.

Upvotes: 0

Dmitri T
Dmitri T

Reputation: 168002

The relevant regular expression would be:

_data\["_as_csrf_token"\] = "(\w+)";

Demo:

enter image description here

More information:

Upvotes: 1

UBIK LOAD PACK
UBIK LOAD PACK

Reputation: 34516

The easiest way is to use boundary extractor:

Set left to:

data["_as_csrf_token"] = "

And right to:

";

If you want to use regex extractor then use:

data\["_as_csrf_token"\] = "[^"]+?";

Upvotes: 0

Related Questions