Question: How can I use RegEx to capture a security token for use within JMeter?

Question

How can I use RegEx to capture a security token for use within JMeter?

Answers 1
Added at 2017-11-30 22:11
Tags
Question

I am using JMeter's Regular Expression Extractor to capture a security token from the first HTTP response header to use in future requests.

The HTTP Response is as follows:

{"token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJNVE8iLCJpYXQiOiIxNTEyMDcxNTg1Iiwic3ViIjoiOTEzNjQ0NCIsInV0ayI6InUvenBESVBzOCtUSlZUaW5tYVBaUjBqd2xyd2lJU1lSRVJ1ZnphNUVzS2s9IiwidmVyIjoiMi4wLjguNjIiLCJuYmYiOjE1MTIwNzEyODV9.4y__KpTFSgkdD_dMAuMiClbSfcmnvdtr0IEoVHFB_Fw","sessionTimeoutSeconds":1800,"profileRequirements":null}

So I'm trying to capture all the Characters where I wrote RANDOMCHARS

{"token":"RANDOMCHARS","sessionTimeoutSeconds":1800,"profileRequirements":null}

I plan to use this site to test any suggestions: https://regexr.com/

Any help would be so far beyond appreciated! =)

Answers to

How can I use RegEx to capture a security token for use within JMeter?

nr: #1 dodano: 2017-11-30 23:11

Code

See regex in use here

"token"\s*:\s*"([^"]*)"

Results

Input

{"token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJNVE8iLCJpYXQiOiIxNTEyMDcxNTg1Iiwic3ViIjoiOTEzNjQ0NCIsInV0ayI6InUvenBESVBzOCtUSlZUaW5tYVBaUjBqd2xyd2lJU1lSRVJ1ZnphNUVzS2s9IiwidmVyIjoiMi4wLjguNjIiLCJuYmYiOjE1MTIwNzEyODV9.4y__KpTFSgkdD_dMAuMiClbSfcmnvdtr0IEoVHFB_Fw","sessionTimeoutSeconds":1800,"profileRequirements":null}

Output

Output below is capture group 1

eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJNVE8iLCJpYXQiOiIxNTEyMDcxNTg1Iiwic3ViIjoiOTEzNjQ0NCIsInV0ayI6InUvenBESVBzOCtUSlZUaW5tYVBaUjBqd2xyd2lJU1lSRVJ1ZnphNUVzS2s9IiwidmVyIjoiMi4wLjguNjIiLCJuYmYiOjE1MTIwNzEyODV9.4y__KpTFSgkdD_dMAuMiClbSfcmnvdtr0IEoVHFB_Fw

Explanation

  • "token" Match this literally
  • \s* Match any number of whitespace characters
  • : Match this literally
  • \s* Match any number of whitespace characters
  • " Match this literally
  • ([^"]*) Capture any character except " into capture group 1
  • " Match this literallly
Source Show
◀ Wstecz