Regexp Variable Extractor¶
Regular Expression Extractors lets you extract values from HTTP responses, using regular expressions.
Extracting variables from HTTP response helps you make your Virtual User have a dynamic behavior. Extracted variables can be injected in Logic Actions or HTTP Request Actions.
The first line displays the extracted variable name. This field is mandatory if you want to inject what you extract. The second line contains tab headers to access:
- Simple Configuration, to easily generate a regular expression,
- Advanced Configuration, for more specific needs,
- Check, to validate the result of your Regexp against a recorded HTTP response.
Note
The response selector, on the right, lets you choose which HTTP response is used for configuring and checking the Regexp Action. So if neither recorded responses nor Validate VU responses are available, you have to configure the Regexp Action blindly.
Tip
Make sure to check our video tutorial on how to create a regexp.
Simple configuration¶
The Regexp Action is used to extract values from both HTTP response headers and body.
Body extraction¶
To extract a value from a response body :
- Select the Configuration tab,
- Select
Body
on the right toggle buttons, - Browse the response body, and select the text you want to extract,
- Blue and green selections appear on the sides of the selected text, it displays the left and right text delimiters,
- Adjust left and right offsets to stretch or shrink the text delimiters,
- The generated regexp is shown on the bottom of the tab, it has the form 'Any text between left delimiter and right delimiter' and can be edited in Advanced mode.
Tip
You can search for Strings or Regular Expressions (JavaScript format) inside the response body:
- Click on the body text area,
- Type CTRL + F (or CMD + F on Mac), a dialog appears on top of the area,
- Type the text to search or a regex,
- Press Enter to start searching for the first term occurrence
- Press CTRL + G (or CMD + G on Mac) to find the next occurrence, or SHIFT + CTRL + G (or SHIFT + CMD + G on Mac) to find the previous one.
Header extraction¶
To extract a value from the headers of an HTTP response :
- Select the Configuration tab,
- Select
Headers
on the right toggle buttons, - Browse the response headers, and select the one whose value you want to extract,
- The generated regexp is shown on the bottom of the tab and can be edited in advanced mode.
Advanced configuration¶
You may start by using the simple mode, and then switch to advanced to customise the generated regexp.
The Advanced tab may fulfil more complex requirements.
The following procedure explains how to configure a Regexp Action:
- Select the Advanced tab,
- Select
Headers
orBody
on the right toggle buttons, depending on where your want to apply the regular expression, - Fill in the
Regexp field
using ORO matcher syntax, - Type the template to extract,
- Select the match number. The regexp may match multiple values in the HTTP response, in such case you can select which value to extract,
- Fill in the default value (if the regexp does not match the HTTP response).
Tip
The response panel only displays the content of the HTTP response Body / Headers. To select the text to extract, use the simple Configuration tab.
Note
The template format:
- $0$ extracts the whole regexp,
- The default
$1$
value, to extract the first group value (a group is what is between a set of parenthesis). E.g. for the regexpcategoryId=(.+?)"
the template$1$
extracts the string matched by(.+?)
, - In case you use multiple groups in the regexp,
$n$
extracts the nth group value. - You can also include arbitrary text in the template. E.g. 'cat$1$' to generate the string 'cat' followed by the content of the first group.
The match number format:
- Random, to select any of the values.
- Select nth, to select a particular value.
- All, to select all values. If you select this option, the generated variable can be used in the ForEach Action.
Check regexp result¶
To check the result of a Regexp action just click on the Check tab.
The check process is automatically launched when this tab is opened. It can also be manually started using the Refresh button.
A table contains the extracted values :
Column name | Description |
---|---|
Extracted variable name | The name of the extracted variable. A single Regexp Action can lead to multiple extracted variables. More information below. |
Extracted variable value | The value of the extracted variable. |
Note
Multiple variables can be generated by a single Regexp Action.
E.g. for an extractor named categoryId
with the regexp value categoryId=(.+?)"
, a Select nth
match number and a template $1$
:
categoryId
: the base variable, it contains the extracted value (or the default value), e.g.FISH
categoryId_g
: the count of groups used in the regexp,categoryId_g0
: the whole extraction, delimiters included, e.g.categoryId=FISH"
,categoryId_gn
: where n=0,1,2 - the groups values.
With an All
match number, multiple variables are generated to be used in the ForEach Action :
categoryId
: always has the default value,categoryId_matchNr
: the number of values extracted, e.g. 5,categoryId_N
: the Nth value extracted,- and for each
categoryId_N
, thecategoryId_N_g
,categoryId_N_g0
andcategoryId_N_gn
generated variables.