---
title: "__regexFunction"
description: "JMeter __regexFunction function reference: syntax, parameters, and practical examples for parameterizing test plans with dynamic values."
url: https://docs.jmeter.ai/functions/regexfunction/
lastUpdated: 2026-10-01
source: docs.jmeter.ai
---

# __regexFunction

*Also documented in context in the [full Functions and Variables reference](/user-manual/functions/#__regexFunction).*

The Regex Function is used to parse the previous response (or the value of a variable) using any regular
expression (provided by user).  The function returns the template string with variable values filled
in.

The `__regexFunction` can also store values for future use.  In the sixth parameter, you can specify
a reference name.  After this function executes, the same values can be retrieved at later times
using the syntax for user-defined values.  For instance, if you enter “`refName`” as the sixth
parameter you will be able to use:

- `\${refName}` to refer to the computed result of the second parameter (“Template for the replacement string”) parsed by this function
- `\${refName_g0}` to refer to the entire match  parsed by this function.
- `\${refName_g1}` to refer to the first group parsed by this function.
- `\${refName_g#}` to refer to the nth group parsed by this function.
- `\${refName_matchNr}` to refer to the number of groups found by this function.

> **Note**
> If using distributed testing, ensure you switch mode (see `jmeter.properties`) so that it’s not a stripping one, see [Bug 56376](https://bz.apache.org/bugzilla/show_bug.cgi?id=56376)

| Name | Required | Description |
| --- | --- | --- |
| First argument | Yes | The first argument is the regular expression         to be applied to the response data.  It will grab all matches.  Any parts of this expression         that you wish to use in your template string, be sure to surround in parentheses.  Example:         `&lt;a href="(.*)"&gt;`.  This will grab the value of the link and store it as the first group (there is         only 1 group).  Another example: `&lt;input type="hidden" name="(.*)" value="(.*)"&gt;`.  This will         grab the name as the first group, and the value as the second group.  These values can be used         in your template string |
| Second argument | Yes | This is the template string that will replace         the function at run-time.  To refer to a group captured in the regular expression, use the syntax:         `$[group_number]$`.  I.e.: `$1$`, or `$2$`.  Your template can be any string. |
| Third argument | No, default=1 | The third argument tells JMeter which match         to use.  Your regular expression might find numerous matches.  You have four choices:                  - An integer - Tells JMeter to use that match.  ‘`1`’ for the first found match, ‘`2`’ for the                 second, and so on - `RAND` - Tells JMeter to choose a match at random. - `ALL` - Tells JMeter to use all matches, and create a template string for each one and then                 append them all together.  This option is little used. - A float number between 0 and 1 - tells JMeter to find the Xth match using the formula:                 (number_of_matches_found * float_number) rounded to nearest integer. |
| Fourth argument | No | If ‘`ALL`’ was selected for the above argument         value, then this argument will be inserted between each appended copy of the template value. |
| Fifth argument | No | Default value returned if no match is found |
| Sixth argument | No | A reference name for reusing the values parsed by this function.         Stored values are `\${refName}` (the replacement template string) and `\${refName_g#}` where “`#`” is the         group number from the regular expression (“`0`” can be used to refer to the entire match). |
| Seventh argument | No | Input variable name.         If specified, then the value of the variable is used as the input instead of using the previous sample result. |

## Related

- [Functions and Variables Guide](/topics/functions-and-variables/)
- [Regex Extractor Builder](/tools/regex-tester/)
- [Full Functions Reference](/user-manual/functions/)
- [Component Reference](/user-manual/component-reference/)
