简体   繁体   English

JMeter和正则表达式提取器

[英]JMeter and Regular Expression Extractor

I am using JMeter and responses have content like this, one per response. 我正在使用JMeter,响应的内容是这样的,每个响应一个。

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

The value of _formkey has to be passed to the next request. 必须将_formkey的值传递给下一个请求。 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. 我使用formkey传递值,它工作正常。 But how can I avoid the other 3 variables getting generated? 但是如何避免生成其他3个变量? Is my regex not 'well-formed" as in not doing a perfect job? 我的正则表达不是“完美的”,就像没有完美的工作一样吗?

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. formkey_g0是匹配的整个字符串, formkey_g1是括号内匹配的部分。 See the examles on the JMeter page. 请参阅JMeter页面上的考试 To quote the relevant section for the purpose of completeness: 引用相关部分以达到完整性:

For example, assume: 例如,假设:

  • Reference Name: MYREF 参考名称:MYREF
  • Regex: name="(.+?)" value="(.+?)" 正则表达式:name =“(。+?)”value =“(。+?)”
  • Template: $1$$2$ 模板:$ 1 $$ 2 $

The following variables would be set: 将设置以下变量:

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

These variables can be referred to later on in the JMeter test plan, as ${MYREF}, ${MYREF_g1} etc 这些变量稍后可在JMeter测试计划中引用,如$ {MYREF},$ {MYREF_g1}等

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. 请注意, MYREF_g0始终是正则表达式的完全匹配,这与在Java和其他编程语言中使用正则表达式一致。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM