Reputation: 33
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
Reputation: 373
Please use the following string to extract the data using ReEx Extractor.
_data\[\"_as_csrf_token\"\] \= \"(.+?)\"\;
As shown in the screenshot below 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
Reputation: 168002
The relevant regular expression would be:
_data\["_as_csrf_token"\] = "(\w+)";
Demo:
\w
is a character class for word characters (alphanumeric, case insensitive)+
is the repititionMore information:
Upvotes: 1
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