Skip to main content

REGEX_REPLACE

The REGEX_REPLACE function searches the text for matches to a regular expression pattern and replaces each match with specified new text.

Use

REGEX_REPLACE( old_text, pattern, new_text )
Replaces characters within the text matching the specified regular expression pattern with new text.

ParameterRequiredDescription
old_textYestext in which to replace some characters
patternYesthe regular expression to match
new_textYesthe text that will replace characters in old_text (supports capture groups)

ReturnsText

Examples

Standardizing Legacy Data (Input Mapping)

You can use REGEX_REPLACE in an Input Mapping formula to transform old data formats into current organizational standards before they are displayed to an approver.

  • Scenario: A "Legacy ID" entered into a trigger form starts with an old system prefix (e.g., "OLD_"), and you want to replace it with the current project prefix ("PROJ-") for the remainder of the workflow.
  • Formula: REGEX_REPLACE(@Trigger.out.LegacyID, "^OLD_", "PROJ-")
  • Logic: The pattern ^OLD_ identifies the specific text at the very beginning of the string. The function then swaps that match with the new "PROJ-" text while leaving the rest of the alphanumeric ID intact.

Masking Sensitive Information (Variable Update)

You can use REGEX_REPLACE within a Variable Update formula to "mask" or anonymize sensitive data before it is recorded in the run history or sent to a Reporting Connector.

  • Scenario: You have a "Personal Identification Number" where only the first and last two digits should be visible in reports for security reasons.
  • Formula: REGEX_REPLACE($SensitiveID, "^(\d{2})\d+(\d{2})$", "$1-***-$2")
  • Logic:
    • (\d{2}): These are capture groups that "remember" the first two and last two digits.
    • \d+: This matches all the digits in the middle of the string.
    • $1-***-$2: The function uses the capture groups to reconstruct the string, displaying the original start ($1) and end ($2) while replacing the middle digits with asterisks.