0
votes

I am trying to extract the last value from the string in Jmeter Regular Expression extractor.

My string

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

I want to get only asdf-U-Yasdf77asdf99.

I tried something like the below, but not correct:

Server.init\(".+", ".+", "([A-Za-z0-9\-]+)"\);
3
What do you mean by saying that your regex is "not correct"? How are you using it and what results you get?Pshemo

3 Answers

1
votes

Using JMeter you need to reference your match group.

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

Your captured match can be accessed by using ${MYWORD}

If you specify using a Match No: above, use the corresponding value to access the match.

1
votes

That regex, while not very beautiful, should work when used correctly. But you need to look at the result of group 1, not the entire match.

So you need to do something like

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

Regular Expression:

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

Matches the following string

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

we can extract the following values in jmeter:

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