问题描述
我想提取Jmeter中最后一次出现的正则表达式.我使用正则提取器表达式来执行此操作,但是我没有最后一次出现.
I would like to extract the last occurence of regular expression in Jmeter.I used Regular Extractor expression to do this, but I can't got the last occurence.
我尝试过:
- 正则表达式:"var1":([[^] +)," var2"
- 模板:$ 1 $
- 比赛编号:-1
- 默认值:expression_matchNr
- Regular expression: "var1":([^"]+),"var2"
- Template : $1$
- Match No : -1
- Default value : expression_matchNr
然后在我的脚本中,我使用了 $ {expression} 变量
Then in my script I used ${expression} variable
我已经测试过 expression_matchNr ,但是它可以给我匹配的次数.
I've tested expression_matchNr but it give me the number of match.
我应该在"比赛编号:"中输入什么?
What should I put in "Match No:" ?
预先感谢
推荐答案
如果有以下输出:
expression=foo
expression_1=foo
expression_2=bar
expression_3=**what you looking for**
expression_matchNr=3
您可以使用JMeter的 __V 函数来获取expression_3
变量的值
You can use JMeter's __V function to get value of expression_3
variable
根据功能的说明:
例如,如果一个变量具有A1,A2和N = 1:
For example, if one has variables A1,A2 and N=1:
-
${A1}
-可以正常工作 -
${A${N}}
-不起作用(嵌套变量引用) -
${__V(A${N})}
-正常运行. A $ {N}变为A1,__ V函数返回A1的值
${A1}
- works OK${A${N}}
- does not work (nested variable reference)${__V(A${N})}
- works OK. A${N} becomes A1, and the __V function returns the value of A1
因此,在您使用的函数中,无论有多少个匹配项,返回最后一个匹配项都将如下所示:
So in your case the function, returning last match no matter how many matches are will look like:
${__V(expression_${expression_matchNr})}
有关什么内容,请参见如何使用JMeter函数系列文章否则可以用功能来完成.
See How to Use JMeter Functions post series on what else can be done with functions.
这篇关于如何在jmeter中的常规Extracor表达式中获得最后一个匹配项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!