Grabbing it all in a JMeter Regular Expression Extractor

I have lately been working with Apache JMeter to generate reports based on the data returned from a series of web service calls (details on how to do this will be in a later posting).

Apache JMeter is an Apache project that is predominately used as a load testing tool for analyzing and measuring the performance of a variety of services. Its main focus is web applications.
I have been struggling for quite some time at how to extract the response of an HTTP Sampler into a variable for later use. In cases where the response is xml, I would just use an XPath Extractor but in this case, the response from the service is HTML HTML is not guaranteed to be well formed xml (XML does not permit end-tag minimization (missing

, etc), unquoted attribute values, and a number of other SGML shortcuts) so an XPath Extractor would periodically throw errors.

The problem I have been struggling with is how to use a Regular Expression Extractor to save the entire HTTP Sampler response to a variable in JMeter. The documentation for the Regular Expression Extractor states that it allows the user to extract values from a server response using a Perl-type regular expression.

After much trial and error, here is the expression that I came up with:


() – grouping

? – Enables the embedded pattern-,attach modifiers. ?i enables case insensitivity, ?m enables multiline treatment of the input, ?s enables single line treatment of the input (it affects how the ‘.’ meta-character is interpreted), and ?x enables extended whitespace comments. We are using ?s to allow the use of ‘.’ to match a newline character.

s – Allows use of . to match a newline character
^ – matches the beginning of a string or line
. – matches everything. Usually this would exclude \n but since we have prefaced our expression with ?s it includes even these.

Here is how I configured my Regular Expression Extractor

Regular Expression Extractor




This entry was posted in Uncategorized. Bookmark the permalink.

8 Responses to Grabbing it all in a JMeter Regular Expression Extractor

  1. Paddy says:

    Thanks !

    Nice explanation and kept it simple!

  2. glinius says:

    Thanks for the post, have never thought of getting the whole response via RegEx.

    I used to get this via Beanshell Post Processor which has “data” pre-defined variable. This “data” is a byte array containing the whole response. Beanshell equivalent will look like:

    String response = new String(data);
    vars.put(“responseVar”, response);

    See blog post on how to use Beanshell for more details

  3. Hans says:

    Thank you! You’ve just saved my day today 🙂

  4. NitinS says:

    Thanks! It helped.

  5. vikas vicky says:

    Thanks Dwain…It works perfectly…Awesome

  6. Chintz says:

    Thanks Dwain. Very nicely explained. It worked for me. Cheers!

  7. Shreya says:

    Thank you. This worked to grab the entire Json response. I need to grab only the bottom half of the response. How can I do that? Thanks in advance.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s