Regex Replace
Audience:
Low-code EngineersSkill Prerequisites:
Actions,Tokens,Regular expressions
Replaces text that matches a regular expression and stores the result in a token. Each row has its own input, pattern and replacement, so one action can clean or reformat several values.
For example, you can keep only the digits of a phone number, or turn 09/27/2026 into 2026-09-27.
This action needs the Scripting feature in your license. If it isn't licensed, the action fails with a "not licensed" error.
Typical Use Cases
- Remove unwanted characters, for example everything but digits from a phone number
- Reformat values, such as dates or codes, by reordering the parts
- Collapse repeated spaces or line breaks in user input
- Mask part of a value, for example all but the last 4 digits of an account number
Don't use it to
- Extract values into tokens. Use Regex or Regex - Multiple Results instead.
- Make HTML safe. Use Sanitize HTML instead. A regex can't reliably remove unsafe HTML.
- Set a token to a fixed value. Use Create/Update Tokens instead.
Related Actions
| Action Name | Description |
|---|---|
| Regex | Gets the first match of one or more patterns, each in its own token. |
| Regex - Multiple Results | Gets every match of one pattern, as CSV, JSON or XML text. |
| Sanitize HTML | Removes unsafe tags and attributes from HTML. |
| Create/Update Tokens | Creates or changes tokens with values you set. |
Comparing the regex actions
| Action | Patterns | Result |
|---|---|---|
| Regex | One or more rules, each with its own pattern, on one Input | The first match of each pattern, each in its own token |
| Regex - Multiple Results | One pattern | Every match, joined into CSV, JSON or XML text |
| Regex Replace | One or more rows, each with its own Input and pattern | The Input with every match replaced |
Input Parameter Reference
| Parameter | Description | Supports Tokens | Default | Required |
|---|---|---|---|---|
| Data | The replacements, one per row. Rows run in order. Each row has the columns below. | See columns | empty | Yes |
| Store in Token | The token that gets the result, for example PhoneDigits. Brackets around the name are removed, so [PhoneDigits] also works. | No | empty string | Yes |
| Input | The text to change, usually a token such as [Phone]. It can use a token set by an earlier row of the same action. | Yes | empty string | Yes |
| Pattern | The pattern to find, for example \D. Every match is replaced. | Only if Apply tokens on pattern is checked | empty string | Yes |
| Replace with | The replacement text. It can refer to groups of the match, for example $1 or ${year}. Leave it empty to remove the matches. See Replacement syntax. | No | empty string | No |
| Apply tokens on pattern | When checked, tokens in Pattern are replaced before matching. See Tokens in the pattern. | No | false | No |
| Compile Regex | Compiles the patterns for faster matching. Compiled patterns run about 30% faster but use more memory, and the first run is about 3 times slower. Use it when the action runs often with the same patterns. | No | false | No |
Output Parameters Reference
| Output | Description |
|---|---|
[<Store in Token>] | One token for each row of Data, with the Input after the replacements. If nothing matches, it's the Input unchanged. |
Replacement syntax
Replace with uses the .NET substitution syntax:
| Syntax | Inserts |
|---|---|
$0 | The whole match |
$1, $2, ... | A numbered group |
${name} | A named group, for example ${year} for (?<year>\d{4}) |
$$ | A literal $ |
Write ${1} instead of $1 when a digit follows, for example ${1}0. Tokens aren't replaced in Replace with, so [Name] is inserted as it is.
Pattern syntax and options
- .NET regular expressions. Patterns use the .NET syntax, such as
\d,\w,\s,(?<name> ), lookaheads and inline options. - Every match is replaced, not only the first one.
- Case is ignored. The action always matches without case sensitivity, so
catalso replacesCatandCAT. To match case, start the pattern with(?-i). - Other options. There are no settings for multiline or singleline mode. Use
(?m)at the start of the pattern so^and$match at each line, or(?s)so.matches line breaks too.
Tokens in the pattern
By default, Pattern is used as it is. Bracket sets such as [a-z] or [0-9] are regex syntax, not tokens, and aren't touched.
When Apply tokens on pattern is checked, the pattern goes through token replacement first. Use it to build a pattern from a value, for example \b[BannedWord]\b. Keep in mind:
- Brackets can be read as tokens. A bracket set whose content matches an existing token name is replaced by that token's value. A set that contains a
:, such as[^:], can be removed. Avoid bracket sets in the pattern when this option is on, or test the pattern carefully. - Token values aren't escaped. Characters such as
.,+,(or?in a token value act as regex syntax. For example, a value ofa.balso matchesaxb.
Considerations
- Rows can build on each other. The Input of each row is read when the row runs, so a row can use the token of an earlier row. See Example 2.
- Don't leave Pattern empty. An empty pattern matches between every character, so a non-empty Replace with is inserted everywhere.
- Invalid patterns fail the action. A syntax error in a pattern, such as an unclosed
(, raises an error when the action runs. - No timeout. The action doesn't set a match timeout. Patterns with nested repetition, such as
(a+)+$, can take a very long time on long inputs. Keep patterns simple and specific.
Examples
To understand how to use the below examples, please see Running Examples.
1. Clean a phone number and reformat a date
The first row removes everything but digits from [Phone], so (555) 123-4567 becomes 5551234567 in [PhoneDigits]. The second row turns a US date in [StartDate], such as 09/27/2026, into 2026-09-27 in [StartDateIso].
{
"Title": "Regex Replace",
"ActionType": "RegexReplacer",
"Description": "Normalize the phone number and start date",
"Parameters": {
"Data": [
{
"TokenName": "PhoneDigits",
"Input": "[Phone]",
"PatternValue": "\\D",
"ReplaceValue": ""
},
{
"TokenName": "StartDateIso",
"Input": "[StartDate]",
"PatternValue": "^(\\d{2})/(\\d{2})/(\\d{4})$",
"ReplaceValue": "$3-$1-$2"
}
],
"ApplyTokensOnPattern": false,
"CompileRegex": false
}
}
2. Clean up a comment
The first row replaces any run of spaces, tabs or line breaks in [Comment] with one space. The second row reads the result of the first row, [CleanComment], and removes the spaces at the start and end.
{
"Title": "Regex Replace",
"ActionType": "RegexReplacer",
"Description": "Collapse whitespace and trim the comment",
"Parameters": {
"Data": [
{
"TokenName": "CleanComment",
"Input": "[Comment]",
"PatternValue": "\\s+",
"ReplaceValue": " "
},
{
"TokenName": "CleanComment",
"Input": "[CleanComment]",
"PatternValue": "^\\s+|\\s+$",
"ReplaceValue": ""
}
],
"ApplyTokensOnPattern": false,
"CompileRegex": false
}
}
3. Mask an account number
This action replaces every digit that has at least 4 more digits after it with *. So 1234567890 becomes ******7890 in [MaskedAccount].
{
"Title": "Regex Replace",
"ActionType": "RegexReplacer",
"Description": "Show only the last 4 digits",
"Parameters": {
"Data": [
{
"TokenName": "MaskedAccount",
"Input": "[AccountNumber]",
"PatternValue": "\\d(?=\\d{4})",
"ReplaceValue": "*"
}
],
"ApplyTokensOnPattern": false,
"CompileRegex": false
}
}
Revised 09/27/2026