count the number of values returned by regex extractor in jmeter

4.1k Views Asked by At

How do I count the number of samples/values returned by jmeter extractors.

I am using regex to get the list of links to a variable using regex extractor. By debug sampler shows that there many values returned. until like 9_g1

PlanLinksArray_9_g=1
PlanLinksArray_9_g0=/hix/admin/planmgmt/viewqhpdetail/gLe8eM5psNUTqo8aYXo20w
PlanLinksArray_9_g1=/hix/admin/planmgmt/viewqhpdetail/gLe8eM5psNUTqo8aYXo20w

How can i get the count of this to a variable in Jmeter??

2

There are 2 best solutions below

0
On

You can get extracted variables count as ${PlanLinksArray_matchNr} it will hold the number of variables like:

PlanLinksArray_1
PlanLinksArray_2
PlanLinksArray_3
etc.

If you need to include match groups as well, like

PlanLinksArray_1_g
PlanLinksArray_1_g0
PlanLinksArray_1_g1
etc.

you'll have to do some scripting.

  1. Add a Beanshell PostProcessor after your Regular Expression extractor
  2. Put the following code into the PostProcessor's "Script" area

    JMeterVariables vars = new JMeterVariables();
    Iterator iterator = vars.getIterator();
    int counter = 0;
    while (iterator.hasNext()) {
        Map.Entry e = (Map.Entry) iterator.next();
        if (e.getKey().startsWith("PlanLinksArray")) {
            counter++;
        }
    }
    
    vars.put("extractedValues", String.valueOf(counter));
    
  3. Number of variables which names start with "PlanLinksArray" will be available as ${extractedValues} variable

See How to use BeanShell: JMeter's favorite built-in component guide for more Beanshell tips and tricks.

0
On

AS per:

it will be called:

PlanLinksArray_9_matchNr : the number of matches found; could be 0