Jayadevan
Jayadevan

Reputation: 1332

JMeter and Regular Expression Extractor

I am using JMeter and responses have content like this, one per response.

<input name="_formkey" type="hidden" value="65aace0b-fa79-4b99-bf20-22c6ef2b043c" />

The value of _formkey has to be passed to the next request. I used regex extractor for this -

input name="_formkey" type="hidden" value="(.+?)" 

This generates quite a few variables

formkey=bec48a21-3955-493e-93c2-97a1f0bf64cf
formkey_g=1
formkey_g0=input name="_formkey" type="hidden" value="bec48a21-3955-493e-93c2-97a1f0bf64cf" 
formkey_g1=bec48a21-3955-493e-93c2-97a1f0bf64cf

I am using formkey to pass the value and it is working fine. But how can I avoid the other 3 variables getting generated? Is my regex not 'well-formed" as in not doing a perfect job?

Upvotes: 1

Views: 815

Answers (1)

Chandranshu
Chandranshu

Reputation: 3669

Your regex is perfectly well formed. You are getting the number of groups and the groups themselves as the other variables. formkey_g0 is the whole string that matches and formkey_g1 is the part that matched within the parentheses. See the examles on the JMeter page. To quote the relevant section for the purpose of completeness:

For example, assume:

  • Reference Name: MYREF
  • Regex: name="(.+?)" value="(.+?)"
  • Template: $1$$2$

The following variables would be set:

  • MYREF: file.namereadme.txt
  • MYREF_g0: name="file.name" value="readme.txt"
  • MYREF_g1: file.name
  • MYREF_g2: readme.txt

These variables can be referred to later on in the JMeter test plan, as ${MYREF}, ${MYREF_g1} etc

Note that MYREF_g0 is always the complete match of the regex which is consistent with the use of regexes in Java and other programming languages.

Upvotes: 3

Related Questions