0

I am trying to do correlation in Jmeter using regular expression. My scenario is:

GUID=1232, awsdqdwe click1 ,GUID=21232 berttt click2, b, GUID=323223,babsjbcjhbcc click3

Here I wish to catch GUID of click 3 value which is in numerical ignore all the alphabetical texts Regular expression : GUID=(.*?)(?#text)click3

But this regular expression takes the leftmost GUID . How do I make it look for first GUID from rightmost boundry match?

rap-2-h
  • 30,204
  • 37
  • 167
  • 263
  • Possible duplicate of [How can I get the last match in regular extracor expression in jmeter?](https://stackoverflow.com/questions/26648257/how-can-i-get-the-last-match-in-regular-extracor-expression-in-jmeter) – Ori Marko Mar 13 '18 at 06:51

2 Answers2

0

Try the following,

String input ="GUID=1232, awsdqdwe click1 ,GUID=21232 berttt click2, b, GUID=323223,babsjbcjhbcc click3"; 
Pattern click3IdPatttern = Pattern.compile("(?<=GUID[=])\\d+(?=[a-zA-Z ,]+?(click3))");
Matcher matcher = click3IdPatttern.Matcher(input);
String id = matcher.find() ? matcher.group() : "";

In my regex "(?<=GUID[=])\\d+(?=[a-zA-Z ,]+?(click3))" , iam using positive lookahead and lookbehind.

Arun Gowda
  • 2,721
  • 5
  • 29
  • 50
  • 1
    Keep it simple: `GUID=(\\d+),? ?(\\w+) click3` – Aniket Sahrawat Mar 13 '18 at 07:14
  • @AniketSahrawat , Keeping it simple is one thing. But readability and keeping the regex generic is equally important. We don't need to capture GUID and click3 which is why I'm using lookahead and look behind. – Arun Gowda Mar 13 '18 at 07:20
  • 1
    That is why we use groups. Btw, if you talk about readability, I think the regex that I suggested is more readable. – Aniket Sahrawat Mar 13 '18 at 07:22
0

The relevant regular expression would be something like:

 GUID=(\d+),.*click3

Demo:

JMeter Regular Expression Extractor

References:

Dmitri T
  • 159,985
  • 5
  • 83
  • 133