Skip to content

Regex Replace

Transform text using the full power of regular expressions. Match complex patterns, use capture groups, and perform sophisticated text transformations that simple find-and-replace can’t handle.

Regex Replace is designed for advanced text manipulation using regular expressions. When you need pattern matching, capture groups, or complex transformations, this is the action to use. For simple literal string replacements, see Search & Replace.

The text you want to perform regex replacement on. Can be any string value from a property, workflow variable, or static text.

Example:

{{contact.phone}}
{{company.description}}
Order #12345-ABC placed on 2024-01-15

The regular expression pattern to match. Enter the pattern directly without delimiters (no surrounding /).

Pattern examples:

\d+ Match one or more digits
[A-Z]{2,4} Match 2-4 uppercase letters
(\w+)@(\w+\.\w+) Capture email parts
^Order #(\d+)-([A-Z]+) Match order format with capture groups
\s+ Match whitespace

The text to replace matches with. Supports capture group references:

  • $1, $2, $3, etc. — Insert captured groups
  • $& — Insert the entire match
  • $$ — Insert a literal dollar sign
  • Leave empty to delete matches

Examples:

$2@$1.com Swap capture groups
[$1] Wrap capture group in brackets
(empty) - Delete matched text
*** Replace with asterisks

Regex flags to modify matching behavior:

FlagNameDescription
(none)DefaultReplace first match only, case-sensitive
gGlobalReplace all matches
iCase insensitiveIgnore case when matching
giGlobal + Case insensitiveReplace all, ignore case
mMultiline^ and $ match line boundaries
gmGlobal + MultilineAll matches with line boundaries
gimAll flagsGlobal, case insensitive, multiline

The text after performing the regex replacement. If no matches are found, returns the original text unchanged.

The number of replacements made, as a string (e.g., “0”, “3”, “10”).

Example 1: Extract and Reformat Phone Numbers

Section titled “Example 1: Extract and Reformat Phone Numbers”

Scenario: Convert phone numbers from (555) 123-4567 to 555.123.4567

Input:

  • Text: (555) 123-4567
  • Pattern: \((\d{3})\)\s*(\d{3})-(\d{4})
  • Replacement: $1.$2.$3
  • Flags: (none)

Output:

  • result: 555.123.4567
  • replacements: 1

Scenario: Partially mask email addresses for privacy.

Input:

  • Text: john.doe@company.com
  • Pattern: (\w{2})\w*@
  • Replacement: $1***@
  • Flags: (none)

Output:

  • result: jo***@company.com
  • replacements: 1

Example 3: Clean Phone Numbers (Remove Non-Digits)

Section titled “Example 3: Clean Phone Numbers (Remove Non-Digits)”

Scenario: Strip all non-numeric characters from a phone number.

Input:

  • Text: +1 (555) 123-4567
  • Pattern: \D
  • Replacement: “ (empty)
  • Flags: g

Output:

  • result: 15551234567
  • replacements: 6

Example 4: Convert camelCase to snake_case

Section titled “Example 4: Convert camelCase to snake_case”

Scenario: Transform variable names from camelCase to snake_case.

Input:

  • Text: getUserEmailAddress
  • Pattern: ([a-z])([A-Z])
  • Replacement: $1_$2
  • Flags: g

Output:

  • result: get_User_Email_Address
  • replacements: 3

(Follow with Text Transform lowercase for get_user_email_address)


Scenario: Get just the domain part of an email address.

Input:

  • Text: user@example.com
  • Pattern: .*@(.+)$
  • Replacement: $1
  • Flags: (none)

Output:

  • result: example.com
  • replacements: 1

Scenario: Replace credit card numbers with masked version.

Input:

  • Text: Payment: 4532-1234-5678-9012
  • Pattern: \b(\d{4})-\d{4}-\d{4}-(\d{4})\b
  • Replacement: $1-XXXX-XXXX-$2
  • Flags: g

Output:

  • result: Payment: 4532-XXXX-XXXX-9012
  • replacements: 1

Scenario: Strip all HTML tags from text.

Input:

  • Text: <p>Hello <strong>World</strong>!</p>
  • Pattern: <[^>]+>
  • Replacement: “ (empty)
  • Flags: g

Output:

  • result: Hello World!
  • replacements: 4

Scenario: Reorder name from “First Last” to “Last, First”.

Input:

  • Text: John Smith
  • Pattern: ^(\w+)\s+(\w+)$
  • Replacement: $2, $1
  • Flags: (none)

Output:

  • result: Smith, John
  • replacements: 1

Scenario: Ensure URLs have https:// prefix.

Input:

  • Text: Visit us at example.com or www.test.com
  • Pattern: \b(www\.)?([a-z0-9-]+\.[a-z]{2,})\b
  • Replacement: https://$1$2
  • Flags: gi

Output:

  • result: Visit us at https://example.com or https://www.test.com
  • replacements: 2

Scenario: Replace multiple spaces/tabs with single space.

Input:

  • Text: Hello World Test
  • Pattern: \s+
  • Replacement:
  • Flags: g

Output:

  • result: Hello World Test
  • replacements: 2

Capture groups let you extract and rearrange parts of matched text:

SyntaxMeaning
(pattern)Create a capture group
$1First capture group
$2Second capture group
$&Entire matched text
$$Literal dollar sign

Example: Pattern (\d{4})-(\d{2})-(\d{2}) with replacement $2/$3/$1

  • Input: 2024-01-15
  • Output: 01/15/2024
PatternMatches
\dSingle digit
\d+One or more digits
\d{4}Exactly 4 digits
\d{2,4}2 to 4 digits
PatternMatches
\wWord character (a-z, A-Z, 0-9, _)
\w+One or more word characters
[A-Z]+Uppercase letters
[a-z]+Lowercase letters
[A-Za-z]+Any letters
PatternMatches
\sSingle whitespace
\s+One or more whitespace
\tTab
\nNewline
PatternMatches
^Start of string (or line with m flag)
$End of string (or line with m flag)
\bWord boundary

To match literal special characters, escape them with \:

\. Match literal period
\( Match literal opening parenthesis
\) Match literal closing parenthesis
\[ Match literal opening bracket
\$ Match literal dollar sign
\\ Match literal backslash
  • Test patterns first — Validate regex patterns with sample data before deploying
  • Use the right flagsg for all occurrences, i for case-insensitive
  • Escape special characters — Use \ before ., (, ), [, ], etc. when matching literals
  • Start simple — Build patterns incrementally, testing each addition
  • Capture only what you need — Use non-capturing groups (?:pattern) when you don’t need to reference the group
  • Check replacements count — Verify matches were found using the replacements output
  • Chain actions — Combine multiple Regex Replace actions for complex multi-step transformations

When to Use Regex Replace vs Search & Replace

Section titled “When to Use Regex Replace vs Search & Replace”
Use CaseRecommended Action
Simple literal replacementSearch & Replace
Pattern matching (digits, letters)Regex Replace
Capture groups and rearrangingRegex Replace
Case-insensitive matchingRegex Replace
Complex text transformationsRegex Replace
Remove specific charactersEither (Regex Replace for patterns)