Monte Chan
Monte Chan

Reputation: 1203

How to extract certain values using regular expression extractor in JMeter?

In the case where I have two identical tags and identical attributes and the only difference is the value, how can I extract the second one?

<data xsi:type="soapenc:string">0</data>
<data xsi:type="soapenc:string">1</data>

I have tried doing the followings.

<data xsi:type="soapenc:string">0</data><data xsi:type="soapenc:string">(.+?)</data>

And assign the value to myID. But when I put in ${myID} in the script, it is using the string "${myID}" instead of the actual value. Is it that the extraction not working? Or do I need to use a different variable for it?

I have a different sampler where I have only one tag. For example,

<data xsi:type="soapenc:string">0</data>

When I do,

<data xsi:type="soapenc:string">(.+?)</data>

and assign to myAnotherID, I can use ${myAnotherID} and the value would be used in the script.

So, why is it that ${myID} does not return the value?

Thanks in advance, Monte

Upvotes: 1

Views: 17358

Answers (1)

Aliaksandr Belik
Aliaksandr Belik

Reputation: 12873

Use the single expression - <data xsi:type="soapenc:string">(.+?)</data> - to get all the matches.
If there are more than one match jmeter will generate specific variables for each match, based on the variable name to which you are trying to extract - like refName_N: myAnotherID_1, myAnotherID_2, ..., myAnotherID_N in your case.
Then you can refer required value via corresponding variable (myAnotherID_1 in your example).

  • Look into Regular Expression Extractor reference for Match Number explanation.
  • Look into this post about extracting and accessing batch of values using Regular Expression Extractor.
  • You can also use Debug Sampler with JMeter Variables = true to see all the variables generated upon extracting batch of values.
  • Look into this post for looping through multiple RegExp Extractor output values without ForEach Controller.

Hope this helps.

Upvotes: 5

Related Questions