Regex extract
Function: Regex extract
This function helps you find and pull out specific pieces of text from a larger body of text. You tell it what kind of pattern to look for using a "Regular Expression" (Regex), and it will give you all the parts of the text that match that pattern. It's like a super-powered search and extract tool for finding structured information within unstructured text.
Input
- Text (STRING, Required): This is the main block of text where you want to search for patterns.
- Regex (STRING, Required): This is the special pattern you define to tell the function exactly what you're looking for. Think of it as a code that describes the structure of the text you want to find (e.g.,
\d\{3\}-\d\{3\}-\d\{4\}for a phone number). Make sure to enter the regex exactly as it would appear in a regex tester. Do not add extra backslashes for string literal escaping (e.g., use\s, not\\s).
Output
- Result (ARRAY of STRING): This action will produce a list of all the text snippets that match your specified Regex pattern. This list will be stored in a variable. By default, this variable will be named
RESULT, but you can choose a different name for it. If no matches are found, the variable will contain an empty list.
Execution Flow
Real-Life Examples
Here are some practical ways you can use the "Regex extract" function:
Example 1: Extracting Email Addresses from a Document
Imagine you have a long document and you need to quickly gather all the email addresses mentioned within it.
- Inputs:
- Text: "Our team can be reached at [email protected] for general inquiries, or [email protected] for sales. You can also contact [email protected]."
- Regex:
\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]\{2,\}\b
- Result: The
RESULTvariable will contain a list:["[email protected]", "[email protected]", "[email protected]"].
Example 2: Finding Product IDs in a Customer Order Note
A customer leaves a note with several product IDs, and you need to extract them to process the order. The product IDs always start with "PROD-" followed by five digits.
- Inputs:
- Text: "Customer wants PROD-12345 and PROD-67890. Also mentioned an old item, PROD-00001, but that's not needed."
- Regex:
PROD-\d\{5\}
- Result: The
RESULTvariable will contain a list:["PROD-12345", "PROD-67890", "PROD-00001"].
Example 3: Pulling out Specific Dates from a Log Entry
You have a system log entry and you want to extract all dates that are in the YYYY-MM-DD format.
- Inputs:
- Text: "Log entry from 2023-10-26. Event occurred at 14:30. Next scheduled check: 2023-10-27. Previous error on 2023-10-25."
- Regex:
\d\{4\}-\d\{2\}-\d\{2\}
- Result: The
RESULTvariable will contain a list:["2023-10-26", "2023-10-27", "2023-10-25"].