How to Use RegEx Extractor in Gatling Projects?

By | 2019-01-29T15:45:32+00:00 January 29th, 2019|Tags: , , |

Regular expressions are very powerful with string manipulation. It’s fast and flexible but a little bit hard to learn. To be able to extract a data in performance test projects, the regular expression is a good fit. Gatling supports Regular Expression usage for data extraction. Let’s see how we can integrate this approach into our Gatling projects.

How to Extract RegEx in Gatling Script?

For this example, we are going to use an XML web service hosted on

There is a calculator web service where you can do addition, multiplication, division and multiplication operations.

Execute POST Command

First, we need to post body data to our web service. We create an exec object that will make a post operation with a body. Body type can be changed according to your web services nature. We are using StringBody as we are going to post a string. The XML payload is hardcoded for this example. You can always create a variable to store the payload.

This scenario will work like a charm. But that’s not enough. We need to validate the response.

We can do different response validations including. We can do status and content validation. This time, we will validate the content.


Secondly, you need to add the check method. This method is where you will make all the validations. Then we add gatling regex method inside of it with a valid regular expression.


Whenever you run tests, you will see that the test has passed. What is missing here is the validation. We useis method to make the validation against the extracted value. As our test data is hardcoded, we can also hardcode the result.

So step by step,

  1. created a POST Command that makes a request,
  2. parse the response with a regular expression
  3. and make validation.

Happy load testing and don’t forget to run your Gatling tests in Loadium.