Regex replace
Function: Regex replace
This action helps you find specific patterns within a piece of text and replace them with new text. It's a powerful tool for cleaning, reformatting, or extracting information from any text you're working with. You define the pattern using a special code (called a "regular expression" or "regex"), and then specify what you want to replace those patterns with.
Input
- Text (STRING): The original text where you want to perform the replacement. This is the text that will be searched for the specified patterns.
- Regex (STRING): The pattern you want to find within the
Text. This pattern uses a special syntax to describe what to look for (e.g., all numbers, all email addresses, specific words or phrases). - Replacement (STRING): The new text that will be inserted wherever the
Regexpattern is found in theText.
Output
- Result (STRING): This is the name of the variable where the final text, after all replacements have been made, will be stored. By default, this variable is named "RESULT".
Execution Flow
Real-Life Examples
Example 1: Standardizing Phone Numbers
Imagine you have a list of phone numbers in various formats (e.g., \(123\) 456-7890, 123-456-7890, 123.456.7890) and you want to standardize them to 1234567890.
- Inputs:
Text:My contact is \(123\) 456-7890 or 123-456-7890.Regex:[^0-9](This pattern means "any character that is NOT a digit from 0-9")Replacement: `` (An empty string, effectively removing the matched characters)
- Result: The variable
RESULTwill containMy contact is 1234567890 or 1234567890.
Example 2: Anonymizing Sensitive Information
You have customer feedback and want to replace all email addresses with [EMAIL_REDACTED] before sharing it to protect privacy.
- Inputs:
Text:Please contact me at [email protected] for more details. My other email is [email protected].Regex:\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]\{2,\}\b(This pattern matches common email address formats)Replacement:[EMAIL_REDACTED]
- Result: The variable
RESULTwill containPlease contact me at [EMAIL_REDACTED] for more details. My other email is [EMAIL_REDACTED].
Example 3: Cleaning Up Product Codes
Your product codes sometimes include extra information like a version number (e.g., -v1.0 or _v2) at the end, and you want to remove these to get the base product code.
- Inputs:
Text:Product-ABC-123-v1.0, Product-XYZ_456_v2, Product-DEF-789Regex:[-_]v\d+\.?\d*(This pattern matches-vor_vfollowed by one or more digits, optionally a dot and more digits)Replacement: `` (An empty string)
- Result: The variable
RESULTwill containProduct-ABC-123, Product-XYZ_456, Product-DEF-789