1
<input type="hidden" name="_csrf"
                    value="40ea7f46-799b-4ca0-b8cd-4adfba082aed" />

Above is the token I am getting in the request output. I am unable to replace this with a regular expression in Regular Expression Extractor of Jmeter.

<input type="hidden" name="_csrf" value="(.+?)" /> is not working.

Please help.

user3627319
  • 395
  • 3
  • 10
  • 19

3 Answers3

2

If your input actually contains a newline character, then you need to account for that in your regex. Furthermore, better be explicit about the valid characters in your regex, .+ is rarely a good thing:

<input type="hidden"\s+name="_csrf"\s+value="([^"]+)"\s*/>
Tim Pietzcker
  • 328,213
  • 58
  • 503
  • 561
1

you have to be careful with the spaces/newlines.

try with following simple regex:

value="(.*?)"\s/>

If it matches more than one element, to add uniquness, you can add name attribute in the regex as follows:

name="_csrf"\s+value="(.*?)"\s/>
Naveen Kumar R B
  • 6,248
  • 5
  • 32
  • 65
0

This is another evidence for not using regular expressions to parse HTML as they are very fragile and sensitive to minimal markup changes. The more robust and resilient solution is using CSS/JQuery Extractor or XPath Extractor instead.

  • The relevant CSS Expression is input[name=_csrf], use value as "attribute"
  • The XPath query to get the value is //input[@name='_csrf']/@value

See How to Load Test CSRF-Protected Web Sites guide for detailed information on bypassing XSRF protection in JMeter tests

Community
  • 1
  • 1
Dmitri T
  • 159,985
  • 5
  • 83
  • 133