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
Please enter at least three characters to search
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

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

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

  • Unlocking Data with Language: Real-World Applications of Text-to-SQL Interfaces
  • Cookies Revisited: A Networking Solution for Third-Party Cookies
  • Blue Skies Ahead: An AI Case Study on LLM Use for a Graph Theory Related Application
  • Artificial Intelligence, Real Consequences: Balancing Good vs Evil AI [Infographic]
  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
Oops! Something Went Wrong

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
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!