David Torrey
David Torrey

Reputation: 1342

Confusing RegEx results

why is the following regex:

"_id":"(.+?)"}\],"componentType":"(.+?)"

for this string:

"name":"in","_id":"a05d91a7-6be0-c252-08e9-bf94cc0be36e","value":"5.6"}],"_id":"e986915c-22db-429f-9fe7-ae2e2ddfa779","refId":"de9ff045-21ce-4833-af34-30f50c129840","failId":"8b723736-a391-fd7e-8d23-7cc72e568f48"},{"outputs":[{"metadata":{"label":{"value":"Output Integer","capco":"U"},"desc":{"value":"Output
Integer.","capco":"U"}},"name":"f7018f5c-057c-6ab9-7300-875c712b87b7","_id":"daad7ae7-356b-57ca-037e-0c4bcb307201"}],"componentType":"model","metadata":{"signature":"ab7e00a928dc79af806b828e1831a95e","zOrder":1,"label":{"lang":"en","value":"BBBBBBBBBBB","capco":"U"},"geom":{"w":150,"x":203,"h":60,"y":324}

pulling everything from the a05d91a7 UUID to the componentType at the bottom, and not from the _id at the bottom? I have (as far as I'm aware) nothing which indicates pulling additional content between the id (.+?) pattern and the componentType pattern?

What I'm trying to pull specifically is the following:

"_id":"daad7ae7-356b-57ca-037e-0c4bcb307201"}],"componentType":"model"

to be clear, the UUID is variable, hense the (.+?)

Upvotes: 2

Views: 33

Answers (2)

Dmitri T
Dmitri T

Reputation: 168082

There is a dedicated JMeter Test Element - JSON Path Extractor which adds JSON support to JMeter.

See Using the XPath Extractor in JMeter (scroll down to "Parsing JSON") for details on the plugin installation and some JSONPath language reference - it is much simpler than regular expressions, less fragile and more human-readable

Upvotes: 0

vks
vks

Reputation: 67968

"_id":"([^"]*)"}],"componentType":"(.+?)"

Use this.See demo.

https://regex101.com/r/uF4oY4/38

The problem with your regex is .*? can expand based on what condition it needs to match ahead.when you use [^"]* its a negation based approach and cannot go beyond a " in any case.

Upvotes: 1

Related Questions