Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to extract multiple values with a regular expression in Jmeter

I am running tests with jmeter and I need to extract with a Regular Expression:

insertar?sIws2kyXGJJA_01== 
insertar?sIws2kyXGJJA_02==

in the following String:

[\"EMBPAGE1_00010001\",\"**insertar?sIws2kyXGJJA_01==**\",1,100,\"%\",300,\"px\",0,\"center\",\"\",\"[\"EMBPAGE1_00010002\",\"**insertar?sIws2kyXGJJA_02==**\",1,100,\"%\",300,\"px\",0,\"center\",\"\",\"
like image 843
Delvis Echeverria Avatar asked Sep 13 '16 21:09

Delvis Echeverria


People also ask

What is regular expression extractor in JMeter?

In JMeter, the Regular Expression Extractor is useful for extracting information from the response. For example, when you request a page and then need to get a link from the page that was downloaded.

How does JMeter handle multiple dynamic values?

The syntax is $1$, $2$ and so on. The count depends on the number of dynamic values you are extracting from the response. In our example we need to extract 3 values, hence we used $1$$2$$3$ which will create 3 groups or variables to store the extracted values, so: $1$ refers to value of “customerName”:”(.

What is $1$ in JMeter?

$1$ to refers to group 1, $2$ to refers to group 2, etc. $0$ refers to whatever the entire expression matches.

What is boundary extractor in JMeter?

to jmeter-plugins. Boundary extractor is a simple and compact version of Regular Expression Extractor: "Allows the user to extract values from a server response using left and right boundaries" You just give the boundaries and it just return the string between them.


2 Answers

In answer given by DMC, you need to add regular expression extractor TWICE to match/retrieve both the values with different Match No. (1, 2). Though it is also correct, suggesting better approach to achieve the same.

Another Approach:

1. Capture Both Values:

You can use Template to capture both the values at the same time, and later, refer it using indexing.

Please check the following screen shot:

enter image description here

Here, we captured both the values using two groups into two different templates, as $1$ and $2$ respectively. Here, templates store the data in the order of the groups specified in regular expression by default. (FYI, you can change the order also by tweaking the order of templates like $2$ and then $1$.)

Now, as in the diagram, we are capturing two values and storing them using templates: $1$ (refers to first group match) and $2$ (refers to second group match)

2. Retrieve Values:

Now, refer these values in your script by using the following syntax:

${insert_values_gn} (n refers to match no.)

eg:

${insert_values_g1} - refers to the first match

${insert_values_g2} - refers to the second match

To make it simple, You can think "insert_values" as list of strings captured using multiple groups and use 'n' (1,2,3 etc) as the index to retrieve the values.

Note: using templates, you can have any number of values can be retrieved using multiple groups and refer to them by indexing, using a single regular expression extractor.

like image 94
Naveen Kumar R B Avatar answered Oct 13 '22 02:10

Naveen Kumar R B


Use super secret operator (Negative match N)enter image description here

UPD: G2 - is in my example, as I extract two groups from each encounter. each encounter is "uuid" in g1 and g2 is second part I need second part here. that's why $2$ template and g2. If your encounters in one group you ll most likely use $1$ template that will place all encounters into g1. If you have one match group you don't actually need _gN ending at all. To understand more the variables after group extraction add a "Debug PostProcessor" and inspect output in TreeView.

It nice two know that control elements like "For each" understand groups and can work with prefix like regexUUID_ and walk through. In most cases it's next you do after extraction.

UPD2. primitive version of regexp in question (insertar\?sIws2kyXGJJA_\d*)==([^[]*) with template $1$$2$ you ll have the first parts in g1 group and the second parts in g2

like image 44
Konstantin Ivanov Avatar answered Oct 13 '22 03:10

Konstantin Ivanov