vvs
vvs

Reputation: 3

JMeter extract all values from regular expression and store in a csv

I am trying to extract all extracted values from regular expression extractor from multiple regular expressions and store it in a csv format.

I have tried for each controller after each extraction of values, how ever controller allows only one variable at a time. I would need to extract multiple variables in a single csv as part of data preparation and input to an another script. Any idea how can i achieve this requirement. Thanks

Upvotes: 0

Views: 3224

Answers (2)

Dmitri T
Dmitri T

Reputation: 168092

  1. Add JSR223 PostProcessor after the Regular Expression Extractor
  2. Put the following code into "Script" area:

    def csv = new File("my.csv")
    1.upto(vars.get("foo_matchNr") as int, {
        csv << vars.get("foo_$it") << System.getProperty("line.separator")  
    })
    
  3. Replate my.csv with the desired name of the CSV file and foo with the reference name of the variable defined in the Regular Expression Extractor

  4. Once you run your script you will see a new CSV file in JMeter's "bin" folder containing values from the Regular Expression Extractor, each value on a new line

    JMeter Write Values from Extractor to CSV file

More information:

Upvotes: 1

sunny_teo
sunny_teo

Reputation: 1999

In regular expression extractor use "Match No." as -1 to get multiple values. Then use each controller to get the values like Eachvariable_1, Eachvariable_2 etc. Alternatively, you can fetch the values directly like var_1, var_2. Here, var is the name of the regular expression created variable.

Then, use JSR223 post processor and write the extracted values in the csv. Hope this helps.

Also, note the below point if you are using For Each Controller:-

JMeter will expose the looping index as a variable named jm__idx. So for example, if your Loop Controller is named FEC, then you can access the looping index through ${__jm__FEC__idx}. Index starts at 0

Upvotes: 0

Related Questions