Formula - replaceregex
Section titled “ Formula - replaceregex”The replaceregex Formula function returns the content with every match of a regular expression replaced by newValue.

Animated walkthrough: on the Order Entry XML of the Order-to-Cash demo, regex first finds the ERP reference ERP-2025-10005; wrapped in replaceregex, the ERP-2025- prefix is replaced by an empty string and 10005 remains.
Syntax
Section titled “ Syntax”replaceregex('pattern', 'newValue', content)Parameters
Section titled “Parameters”| Parameter | Required | Description |
|---|---|---|
'pattern' |
Yes | A .NET regular expression. Write backslashes once, for example '\d+'; see the Formula language rules. |
'newValue' |
Yes | The text to substitute for each match. $1, $2, and so on insert the capturing groups of the match (Example 4). |
content |
Yes | The text to change: body, context, or the result of another function, such as xPath2. |
Returns
Section titled “Returns”The content with all matches replaced. Content without a match is returned unchanged. When the content holds several values, the replacement runs on each value: replaceregex('a', 'b', …) on the two values aa and ca returns bb and cb.
Examples
Section titled “ Examples”Example 1: Mask every digit
Section titled “Example 1: Mask every digit”<ProjectNumber>1401518</ProjectNumber>Formula
Section titled “Formula”replaceregex('[0-9]', 'X', body)Result
Section titled “Result”<ProjectNumber>XXXXXXX</ProjectNumber>
Each digit is a separate match, so all seven digits are replaced one by one.
Example 2: Replace a fixed word
Section titled “Example 2: Replace a fixed word”<Action>DELETE</Action>Formula
Section titled “Formula”replaceregex('DELETE', 'UPDATE', body)Result
Section titled “Result”<Action>UPDATE</Action>
A pattern without special characters matches the word as is; replace gives the same result without regular expression syntax.
Example 3: Mask an element value
Section titled “Example 3: Mask an element value”<Company>400</Company>Formula
Section titled “Formula”replaceregex('<Company>[0-9]+</Company>', '<Company>XXX</Company>', body)Result
Section titled “Result”<Company>XXX</Company>
The pattern matches the whole element, so newValue writes the tags back around the mask.
Example 4: Build one value per record with capturing groups
Section titled “Example 4: Build one value per record with capturing groups”xPath2 returns each inner TypedPollingResultSet0 record. The pattern captures Company, Activity, and Action, and '$1|$2|$3' replaces the whole record with the three captured values.
<TypedPolling> <TypedPollingResultSet0> <TypedPollingResultSet0> <ProjectNumber>1401518</ProjectNumber> <Company>400</Company> <Activity>1000</Activity> <Version>20250301060028</Version> <Action>DELETE</Action> </TypedPollingResultSet0> <TypedPollingResultSet0> <ProjectNumber>1401518</ProjectNumber> <Company>400</Company> <Activity>1001</Activity> <Version>20250301060028</Version> <Action>DELETE</Action> </TypedPollingResultSet0> <TypedPollingResultSet0> <ProjectNumber>4831351</ProjectNumber> <Company>355</Company> <Activity>1063</Activity> <Version>20250301060028</Version> <Action>DELETE</Action> </TypedPollingResultSet0> <TypedPollingResultSet0> <ProjectNumber>9233120</ProjectNumber> <Company>700</Company> <Activity>3400</Activity> <Version>20250301060028</Version> <Action>DELETE</Action> </TypedPollingResultSet0> <TypedPollingResultSet0> <ProjectNumber>9402000</ProjectNumber> <Company>734</Company> <Activity>5104</Activity> <Version>20250301060028</Version> <Action>DELETE</Action> </TypedPollingResultSet0> </TypedPollingResultSet0></TypedPolling>Formula
Section titled “Formula”replaceregex('.+<Company>(.+)</Company>.+<Activity>(.+)</Activity>.+<Action>(.+)</Action>','$1|$2|$3',xPath2('/TypedPolling/TypedPollingResultSet0/TypedPollingResultSet0',body))Result
Section titled “Result”400|1000|DELETE400|1001|DELETE355|1063|DELETE700|3400|DELETE734|5104|DELETE
Five records give five unique values, each built from the Company, Activity, and Action of one record.
- To replace plain text without regular expression syntax, use replace; it treats every character literally.
- To extract matches instead of replacing them, use regex or regexGroup.