vb381
vb381

Reputation: 181

How to create regex

can somebody help me how to create regex from this? I need only text after a_n: " so I need only this text. e.g. jgoijODIJGojsklfj4dgdg_797gsdg-df_gsdfh-dhfGSDhfdsg-dfg

{
  "a_n": "jgoijODIJGojsklfj4dgdg_797gsdg-df_gsdfh-dhfGSDhfdsg-dfg",
  "type": "something",
  "uuser": "userid",
  "expire": "6018"
}

Upvotes: 0

Views: 84

Answers (5)

Dmitri T
Dmitri T

Reputation: 168122

JMeter's Regular Expression Extractor uses Perl-5 style regular expressions so the relevant configuration would be:

  • Regular Expression: "a_n": "(.+?)"
  • Template: $1$

Also be aware that it makes more sense to use JSON Extractor to work with JSON responses. The relevant JSON Path query would be as simple as $.a_n

Demo:

JMeter JSON Path Extractor

More information: API Testing With JMeter and the JSON Extractor

Upvotes: 0

Masud Jahan
Masud Jahan

Reputation: 2978

To extract this in JMeter:

  1. Add a jp@gc - JSON Path Extractor under your request sampler.

  2. To extract the required data, you have to set like this:

enter image description here

  1. Your extracted value will be saved in the variable Jsonvar.

  2. Now You can use this variable other subsequent requests.

Upvotes: 0

Ashraful Karim Miraz
Ashraful Karim Miraz

Reputation: 725

Please have a look (how to use a regular expression to extract json fields?)

regex should be,

/"a_n":\ ?"((\\"|[^"])*)"/i

Upvotes: 1

filype
filype

Reputation: 8380

You can achieve this with JSONStream.

cat file.json | JSONStream '.a_n'

And also with jq:

jq .a_n file.json

Upvotes: 1

LW001
LW001

Reputation: 2893

If you can, just use a JSON parser to get the value. Otherwise you can use

/{.*\"a_n\": \"(.*)\".*/

Upvotes: 1

Related Questions