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.
Overview
Section titled “Overview”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.
Configuration
Section titled “Configuration”Input Fields
Section titled “Input Fields”Text to Process (Required)
Section titled “Text to Process (Required)”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-15Regex Pattern (Required)
Section titled “Regex Pattern (Required)”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 whitespaceReplacement Text (Required)
Section titled “Replacement Text (Required)”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 asterisksFlags (Optional)
Section titled “Flags (Optional)”Regex flags to modify matching behavior:
| Flag | Name | Description |
|---|---|---|
| (none) | Default | Replace first match only, case-sensitive |
| g | Global | Replace all matches |
| i | Case insensitive | Ignore case when matching |
| gi | Global + Case insensitive | Replace all, ignore case |
| m | Multiline | ^ and $ match line boundaries |
| gm | Global + Multiline | All matches with line boundaries |
| gim | All flags | Global, case insensitive, multiline |
Output Fields
Section titled “Output Fields”result (String)
Section titled “result (String)”The text after performing the regex replacement. If no matches are found, returns the original text unchanged.
replacements (String)
Section titled “replacements (String)”The number of replacements made, as a string (e.g., “0”, “3”, “10”).
Examples
Section titled “Examples”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
Example 2: Mask Email Addresses
Section titled “Example 2: Mask Email Addresses”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)
Example 5: Extract Domain from Email
Section titled “Example 5: Extract Domain from Email”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
Example 6: Redact Credit Card Numbers
Section titled “Example 6: Redact Credit Card Numbers”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
Example 7: Remove HTML Tags
Section titled “Example 7: Remove HTML Tags”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
Example 8: Format Names (Last, First)
Section titled “Example 8: Format Names (Last, First)”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
Example 9: Add Protocol to URLs
Section titled “Example 9: Add Protocol to URLs”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
Example 10: Normalize Whitespace
Section titled “Example 10: Normalize Whitespace”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 Group Reference
Section titled “Capture Group Reference”Capture groups let you extract and rearrange parts of matched text:
| Syntax | Meaning |
|---|---|
(pattern) | Create a capture group |
$1 | First capture group |
$2 | Second 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
Common Patterns
Section titled “Common Patterns”Digits and Numbers
Section titled “Digits and Numbers”| Pattern | Matches |
|---|---|
\d | Single digit |
\d+ | One or more digits |
\d{4} | Exactly 4 digits |
\d{2,4} | 2 to 4 digits |
Text and Characters
Section titled “Text and Characters”| Pattern | Matches |
|---|---|
\w | Word 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 |
Whitespace
Section titled “Whitespace”| Pattern | Matches |
|---|---|
\s | Single whitespace |
\s+ | One or more whitespace |
\t | Tab |
\n | Newline |
Boundaries
Section titled “Boundaries”| Pattern | Matches |
|---|---|
^ | Start of string (or line with m flag) |
$ | End of string (or line with m flag) |
\b | Word boundary |
Special Characters
Section titled “Special Characters”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 backslashBest Practices
Section titled “Best Practices”- Test patterns first — Validate regex patterns with sample data before deploying
- Use the right flags —
gfor all occurrences,ifor 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 Case | Recommended Action |
|---|---|
| Simple literal replacement | Search & Replace |
| Pattern matching (digits, letters) | Regex Replace |
| Capture groups and rearranging | Regex Replace |
| Case-insensitive matching | Regex Replace |
| Complex text transformations | Regex Replace |
| Remove specific characters | Either (Regex Replace for patterns) |
Related Actions
Section titled “Related Actions”- Search & Replace — Simple literal text replacement
- Match Regex — Extract data using regex without replacing
- Text Transform — Basic text transformations (uppercase, lowercase, trim)