Overview
This node applies a regular expression (regex) pattern to input text, extracting matches and capture groups according to the specified pattern and flags. It is useful for parsing, validating, or extracting structured data from unstructured text fields in workflows.
Common scenarios include:
- Extracting specific information such as email addresses, phone numbers, or custom patterns from text.
- Validating text formats against complex patterns.
- Splitting or capturing parts of strings for further processing.
For example, you could use this node to extract named groups from log entries or to find all occurrences of a pattern within a large text block.
Properties
| Name | Meaning |
|---|---|
| Text to Match | The input text on which the regex will be applied. |
| Regex Pattern | The regex pattern to use (without enclosing slashes). Supports named and unnamed capture groups. |
| Flags | Regex flags to modify matching behavior. Options: Dot All (s), Global (g), Ignore Case (i), Multiline (m), Sticky (y), Unicode (u). |
| Keep Full Match | Whether to include the entire matched string as match in the output. If false, only capture groups are output. |
Output
The output is an array of JSON objects, each representing one match found in the input text.
Each output object contains:
- A
matchfield (if "Keep Full Match" is enabled) with the full matched substring. - Named capture groups as individual fields if defined in the regex pattern.
- Unnamed capture groups as fields named
group1,group2, etc.
If the global flag (g) is set, multiple matches are returned as separate items; otherwise, only the first match is returned.
No binary data is produced by this node.
Example output JSON for a match with named groups:
{
"match": "John Doe",
"firstName": "John",
"lastName": "Doe"
}
If "Keep Full Match" is disabled, the match field is omitted.
Dependencies
- No external services or API keys are required.
- Uses JavaScript's built-in
RegExpclass for regex operations. - No special environment variables or n8n credentials needed.
Troubleshooting
- Invalid regex pattern error: If the regex pattern is malformed, the node throws an error indicating the issue. Double-check your regex syntax.
- No matches found: If no matches exist for the given pattern and text, the node outputs an empty array.
- Flags misuse: Using incompatible flags together (e.g., sticky with global) may cause unexpected results. Review regex flag usage.
- Empty input text or pattern: Ensure both "Text to Match" and "Regex Pattern" are provided and non-empty.