【问题标题】:How to get the particular word from response in jmeter Regular Expression extractor如何从jmeter正则表达式提取器中的响应中获取特定单词
【发布时间】:2014-11-27 20:38:43
【问题描述】:

我正在尝试从 Jmeter 正则表达式提取器中的字符串中提取最后一个值。

我的字符串

Server.init("asdfasd4ffffasdf", "http://x.x.x.x:8888/", "asdf-U-Yasdf77asdf99");

我只想得到asdf-U-Yasdf77asdf99

我尝试了类似下面的方法,但不正确:

Server.init\(".+", ".+", "([A-Za-z0-9\-]+)"\);

【问题讨论】:

  • 你说你的正则表达式“不正确”是什么意思?你是如何使用它的,你得到了什么结果?

标签: java regex jmeter


【解决方案1】:

使用JMeter,您需要引用您的匹配组。

Reference Name: MYWORD
Regular Expression: Server\.init\("[^"]+", "[^"]+", "([^"]+)"\);
Template: $1$

可以使用${MYWORD}访问您捕获的匹配项

如果您使用上面的Match No: 指定,请使用相应的值来访问匹配项。

【讨论】:

  • 太棒了。它会起作用,但我从你的解决方案中改变了一点。 Server.init(".+?", ".+?", "(.+?)");
【解决方案2】:

该正则表达式虽然不是很漂亮,但在正确使用时应该可以工作。但是你需要看第一组的结果,而不是整场比赛。

所以你需要做类似的事情

Pattern regex = Pattern.compile("Server\\.init\\(\"[^\"]+\", \"[^\"]+\", \"([A-Za-z0-9\\-]+)\"\\);");
Matcher regexMatcher = regex.matcher(subjectString);
if (regexMatcher.find()) {
    ResultString = regexMatcher.group(1);
}

【讨论】:

    【解决方案3】:

    正则表达式:

    Server.init\("(.+?)",\s"(.+?)",\s"(.+?)"
    

    匹配以下字符串

    Server.init("asdfasd4ffffasdf", "http://x.x.x.x:8888/", "asdf-U-Yasdf77asdf99"
    

    我们可以在jmeter中提取以下值:

    • $1 值 = asdfasd4ffffasdf
    • $2 值 = http://x.x.x.x:8888/
    • $3 值 = asdf-U-Yasdf77asdf99

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-07
      • 1970-01-01
      • 1970-01-01
      • 2012-09-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多