Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
893 views
in Technique[技术] by (71.8m points)

regex - 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","","
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...