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
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

How are you handling the data revolution? We want your take on what's real, what's hype, and what's next in the world of data engineering.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

SBOMs are essential to circumventing software supply chain attacks, and they provide visibility into various software components.

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

  • From Java 8 to Java 21: How the Evolution Changed My Developer Workflow
  • Essential JVM Tools for Garbage Collection Debugging
  • Beyond Java Streams: Exploring Alternative Functional Programming Approaches in Java
  • How You Clear Your HTML5 Canvas Matters
  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 user avatar
Manojkumar Tenali
·
Updated Feb. 20, 18 · Tutorial
Likes (6)
Comment
Save
Tweet
Share
66.7K Views

Join the DZone community and get the full member experience.

Join For Free

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

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

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 100
  • Nashville, TN 37211
  • [email protected]

Let's be friends: