0

I want to take CSRF value with regex extractor.

enter image description here

Then use that variable to my post parameter.

enter image description here

But there is space in csrf parameter.

enter image description here

How to get rid that space? Thanks for your help

This is source csrf which i take csrf

enter image description here

Boma Anjang
  • 132
  • 1
  • 10

3 Answers3

3

I don't get the requirement of ? in the regex where it captures each character individually as a full match and in capturing group 1. Check the demo here. But you can add that if it's required for this particular usecase with jmeter.

.+ captures any character including space characters.

You can either do (\S+) to capture all non space characters as you don't have space characters in the middle or (\w+) to capture all word characters as you only have letters and numbers in your string.

EDIT

Sorry I got your question wrong the first time. Here is a regex that captures the value field of csrfmiddlewaretoken on first capturing group.

name="csrfmiddlewaretoken"\svalue="\s?(\w+)"

Regex Demo

This should omit any leading space characters in the secret. If this didn't work, I suspect that you have an additional space added where you assign this extracted values to the variable.

2
\s*([1-9]+.*?)

Try this and see.

Update

Try this: This must work.

name="csrfmiddlewaretoken"\svalue="([^”]+?)"
1
  1. Double check the place where you're assigning the variable, the regular expression extractor per se won't add any whitespaces anywhere, you can check the extracted variable value using Debug Sampler and View Results Tree listener combination.

  2. Using regular expressions for parsing HTML is not the best idea, I would suggest going for CSS Selector Extractor instead, the relevant configuration would be as simple as:

    enter image description here

More information: CSS Selector Reference

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