DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • JSON-Based Serialized LOB Pattern
  • Mule 3 DataWeave(1.x) Script To Resolve Wildcard Dynamically
  • Exploring Exciting New Features in Java 17 With Examples
  • Reversing an Array: An Exploration of Array Manipulation

Trending

  • How to Evaluate Coding Agents With Harbor Framework, Python, Docker
  • Decoupling a Data Pipeline From the Tables It Was Never Supposed to Depend On
  • Member Spotlight: Raghava Dittakavi
  • You Do Not Need a PhD to Become an AI Engineer: The Essential Skill Stack

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Data Engineering
  3. Data
  4. Using Regular Expression Extractor in JMeter

Using Regular Expression Extractor in JMeter

In this tutorial, learn what the regular expression extractor is for, and how to use it with JMeter to capture dynamic values.

By 
Manojkumar Tenali
·
Updated Feb. 20, 18 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
67.2K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

The regular expression extractor is used to capture the dynamic data- from the response header or body, from the main sample or subsamples, or even from another JMeter variable- and store it into a variable for future use. It allows the user to extract values from a server response using a Perl-type regular expression. As a post-processor, this element will execute after each Sample request in its scope, applying the regular expression, extracting the requested values, generating the template string, and storing the result in the given variable name.

Capture7.PNG

How to Use Regular Expression Extractor to Capture Dynamic Values

capture8.png

If the match number is set to a non-negative number, and a match occurs, the variables are set as follows:

  • refName – the value of the template

  • refName_gn, where n=0,1,2 – the groups for the match

  • refName_g – the number of groups in the Regex (excluding 0)

If no match occurs, then the refName variable is set to the default (unless this is absent). Also, the following variables are removed:

  • refName_g0

  • refName_g1

  • refName_g

If the match number is set to a negative number, then all the possible matches in the sampler data are processed. The variables are set as follows:

  • refName_matchNr – the number of matches found; could be 0

  • refName_n, where n = 1, 2, 3 etc. – the strings as generated by the template

  • refName_n_gm, where m=0, 1, 2 – the groups for match n

  • refName – always set to the default value

  • refName_gn – not set

Note that the refName variable is always set to the default value in this case, and the associated group variables are not set.

To verify the regular expression, we can use either regular expression tester from JMeter itself, or we have a good website to validate the regular expression, www.regexpal.com.

Character classes
. any character except newline
\w \d \s word, digit, whitespace
\W \D \S not word, digit, whitespace
[abc] any of a, b, or c
[^abc] not a, b, or c
[a-g] character between a & g
Anchors
^abc$ start / end of the string
\b word boundary
Escaped characters
\. \* \\ escaped special characters
\t \n \r tab, linefeed, carriage return
\u00A9 unicode escaped ©
Groups & Lookaround
(abc) capture group
\1 backreference to group #1
(?:abc) non-capturing group
(?=abc) positive lookahead
(?!abc)

negative lookahead

Practical Exposure

If the request parameters contain multiple values as mentioned below, we have to capture all the values and subsequently pass them.

Capture9

We have to give the match number attribute as -1 to capture all the values in the reference name, as below:

Capture10

If the match number is set to a negative number, then all the possible matches in the sampler data are processed. The variables are set as follows:

  • refName_matchNr – the number of matches found; could be 0

  • refName_n, where n = 1, 2, 3 etc. – the strings as generated by the template

  • refName_n_gm, where m=0, 1, 2 – the groups for match n

  • refName – always set to the default value

  • refName_gn – not set

Note that the refName variable is always set to the default value in this case, and the associated group variables are not set.

Bookid_matchNr gives the total number of matches; in this example, it is shown as 4:

Capture11https://performanceengineeringsite.wordpress.com/2017/07/29/using-regular-expression-extractor-in-jmeter-part-2/

Template Strings Data (computing) Requests Data Types Pass (software) Extract Exposure (radiation) Attribute (computing) Element

Opinions expressed by DZone contributors are their own.

Related

  • JSON-Based Serialized LOB Pattern
  • Mule 3 DataWeave(1.x) Script To Resolve Wildcard Dynamically
  • Exploring Exciting New Features in Java 17 With Examples
  • Reversing an Array: An Exploration of Array Manipulation

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook