Jmeter函数助手10-regexFunction

发布时间 2023-05-20 16:08:08作者: dabeen

regexFunction函数用于对上一个请求进行正则表达式提取处理,类似正则表达式。

  • 用于从前一个请求搜索结果的正则表达式:填入正则表达式
  • Template for the replacement string, using groups from the regular expression. Format is $[group]$. Example $1$:填入匹配模板
  • Which match to use. An integer 1 or greater, RAND to indicate JMeter should randomly choose, A float, or ALL indicating all matches should be used ([1]):当正则表达式获取到多个值时你想要获得第几个匹配值,填入“ALL”表示获取所有,填入“RAND”表示随机一个,填入“1”表示获取第一个,填入“2”表示获取第二个
  • Between text. If ALL is selected, the between text will be used to generate the results ([""]):填入前缀,当上一个选项填入“ALL”时则在返回结果中增加前缀连接所有值
  • Default text. Used instead of the template if the regular expression finds no matches ([""]):缺省值,当正则表达式获取无数据时则返回该值
  • 存储结果的变量名(可选)
  • Input variable name containing the text to be parsed ([previous sample])

 

1、下图是regexFunction函数和正则表达式组件的对比

2、regexFunction函数相当于正则表达式,故我们先创建一个请求得到结果

 

3、在regexFunction函数填入正则表达式信息等调试取样器${__regexFunction(class=mnav>(.*?)</a,$1$,ALL,&,FAIL,,)}

4、重命名后,也可以通过重用名+不同参数获取一些值。${__regexFunction(class=mnav>(.*?)</a,$1$,3,,FAIL,name,)} 

${name_g0}:返回正则表达式命中的内容

${name_g1}:返回正则表达式提取的内容

${name_matchNr}:正则表达式共获取几个匹配值