1

I have a JMeter HTTP Request that returns

{
    "Token" : "VwAMVWXTakkdffdkEj1I9IiTr8DlYa89fK4yimmQNWSitIY1qBb1Qbs1FU9CfZHWMMlTed3hHOaBD7vJGNh9ZugFZuANtAomk17vIjg3Zgl1Fp0kulb6UTsbnkyyGNwNMGR"
}

in the response data. The string after the colon will change each time. I need this string to then be passed to another HTTP request. I have the rest set up but I am struggling with the regex, I get the default constantly.

Currently the regex looks like -

"Token":"(.+?)" 

but doesn't work.

Can anyone help?

Thanks

Chris Kerr
  • 161
  • 1
  • 14

4 Answers4

2

Use a positive lookbehind,

(?<=\"Token\" : ).*

It matches all the characters which are just after to the string "Token" :

DEMO

OR

(?<=\"Token\"\s:\s\")[^\"]*

If you want the strings inside double quotes then use above regex.

DEMO

Below regex would capture the matched characters,

(?<=\"Token\"\s:\s\")([^\"]*)
Avinash Raj
  • 172,303
  • 28
  • 230
  • 274
1

Your return is JSON data, so the best option would be to handle it as JSON, which also would make your application far easier to maintain and evolve, when the data you are handling gets more complicated than just one attribute. Plus, you can handle it easily in JavaScript. Suggested reads:

Community
  • 1
  • 1
mdrg
  • 3,242
  • 2
  • 22
  • 44
1

Your regular expression needs to account for whitespace. I'd recommend using Regular Expression Extractor, which will make this alot easier for you.

Reference Name: FOO
Regular Expression: "Token" : "(.+?)"
Template: $1$

Use corresponding variable to access the match. ${FOO}

The variables are set as follows:

FOO_matchNr - Number of matches found, possibly 0
FOO_n       - (n = 1, 2, etc..) Generated by the template
FOO_n_gm    - (m = 0, 1, 2) Groups for the match (n) 
FOO         - By itself it is always set to the default value
FOO_gn      - Not set at all
hwnd
  • 69,796
  • 4
  • 95
  • 132
0

You can use regex ([^"]+) when you have received response from HTTP request.

Example:

"Token":([^"]+) --> Not required to add double quotation.