简体   繁体   English

JMeter-选择正则表达式的一部分

[英]JMeter - Selecting Part of a Regular Expression

I have a JMeter Regular Expression Extractor which searches for the following regular expression: 我有一个JMeter正则表达式提取器,它搜索以下正则表达式:

myId=[0-9]{10}

This retrieves the 10 digit numeric id number from my websites form. 这将从我的网站表单中检索10位数字的ID号。 I then set a "Reference Name" of myId for the id number. 然后,我为ID号设置myId的“引用名称”。 My template value is $0$ and my match No. is set to blank. 我的模板值为$ 0 $,我的匹配号设置为空白。

In my HTTP Request, I then pass a parameter value of: 然后在我的HTTP请求中,传递参数值:

${myId}

When I run my JMeter test, it inserts text in the form of: 当我运行JMeter测试时,它将以以下形式插入文本:

myId=myId=1234567890

How do I get rid of the duplicate myId=? 如何摆脱重复的myId =?

Not sure about JMeter's implementation of RegEx but normally 不确定JMeter的RegEx实现,但通常情况下

myId=[0-9]{10}

would match everything, including myId= . 将匹配所有内容,包括myId= What you need is to define capture groups that you want extracted using () and then you will reference the capture group array and get the item you want. 您需要使用()定义要提取的捕获组,然后将引用捕获组数组并获取所需的项。 Eg 例如

myId=([0-9]{10})

group 0 would still be the whole thing but group 1 would be just the numeric portion as delimited by (), ie without myId= . 组0仍然是全部,但组1只是由()分隔的数字部分,即没有myId= Hope this helps. 希望这可以帮助。

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

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