Abhishek Sharma
Abhishek Sharma

Reputation: 31

for loop doesn't show all values after extracting from regex

These are the steps, I am working on:

  1. I have an HTTP Request sampler which returns a list of 35 numbers in random form (4, 2, 1, 3....35, 34) which I have extracted via regEx.
  2. Now I want to get each and every numbers in a variable so I used again regEx with expression (.+?)(,) with 'Match no. (0 for Random) value as -1, on 'JMeter variable' from step# 1 above.
  3. When I use for loop in Beanshell Postprocessor to extract the values from step# 2, I get to see only 34 values?

Web application shows all 35 values, in fact step#1 shows all 35 values in that list as well?

    int i;
    for (i=1;i<=35;i++) {

        int matches = Integer.parseInt(vars.get("Number_" +i));
        log.info("Value of matches: " +matches);

    }

Upvotes: 0

Views: 52

Answers (1)

timbre timbre
timbre timbre

Reputation: 13980

The last number does not have a comma after it, so it will not match the regex (.+?)(,)

Since you are expecting numbers (and only want to match numbers), I suggest changing your regex extractor to:

Regular Expression: ([0-9]+)

which mean you are extracting one or more occurrences of digits. That way you will be getting (as in your example)

Number_1=4
Number_2=2
Number_3=1
...
Number_35=34
Number_matchNr=35

Upvotes: 0

Related Questions