Find And Replace
This document explains the Find And Replace node, which allows you to search for and replace specific words, phrases, or patterns within text content.
Node Inputs
Required Fields
-
Input: The text content that will be processed for replacements
-
Replacements: A list of find/replace pairs to apply, with each pair containing:
- Find word: The text to search for
- Replace with: The text to use as replacement
Node Output
- Output Text: The resulting text after all replacements have been applied
Node Functionality
The Find And Replace node searches for specific words, phrases, or patterns in text and replaces each occurrence with new text. It processes multiple replacements in a single operation, making it efficient for batch text editing tasks.
Key capabilities include:
- Multiple replacements in one operation
- Support for exact match replacements
- Basic regular expression pattern matching (limited support)
When to Use
The Find And Replace node is particularly valuable in scenarios requiring text transformation and standardization. Common use cases include:
- Content Updating: Replace outdated terminology with current terms
- Data Cleaning: Remove or replace unwanted characters and formatting
- Text Standardization: Ensure consistent terminology across documents
- Template Customization: Replace placeholder text with personalized content
- Format Conversion: Transform data from one format to another
Some specific examples:
- Replacing product names across marketing materials
- Standardizing date formats in exported data
- Removing sensitive information from documents
- Converting between US and UK English spelling
- Replacing placeholders like
{{name}}
with actual customer names
Using Regular Expressions
The Find And Replace node supports basic regular expressions (regex) for pattern matching. When using regex:
- Regular expression patterns must be wrapped in forward slashes (
/pattern/
) with any flags at the end - Without the proper slashes, the node will treat the pattern as literal text
Limitations
- Capture groups are not supported: While regex patterns can match text, you cannot use capture groups (
$1
,$2
, etc.) in the replacement text - For complex regex replacements with capture groups, use the Run Code node or the custom node feature with Python instead
Working Regex Examples
- Case-Insensitive Matching
- Clean Up Extra Spaces
- Remove HTML Tags
- Redact Phone Numbers
- Remove Line Breaks
Common Regex Flags
i
: Case-insensitive matchingg
: Global matching (replace all occurrences)s
: Dotall mode (makes.
match newlines)m
: Multiline mode (makes^
and$
match line boundaries)
Loop Mode Pattern
Alternative for Complex Replacements
For more advanced regex operations, especially those requiring capture groups, use the Run Code node with Python:
Important Considerations
- Replacements are processed in the order they are defined
- Multiple replacements can interfere with each other if not planned carefully
- Case-sensitive by default (use regex with ‘i’ flag for case-insensitive)
- Regex patterns require proper slashes (
/pattern/
) to be interpreted correctly - Capture groups are not supported - use the Run Code node or the custom node feature with Python instead
- For multiline text operations, use the ‘s’ flag to make ’.’ match newlines
Troubleshooting Common Issues
Issue | Solution |
---|---|
Regex not working | Ensure pattern is wrapped in /pattern/ with proper flags |
Capture groups not working | Use Run Code node with Python regex instead |
Multiline text not matching | Add ‘s’ flag: /pattern/s |
Case sensitivity issues | Add ‘i’ flag: /pattern/i |
Only first match replaced | Add ‘g’ flag: /pattern/g |
In summary, the Find And Replace node is a powerful text manipulation tool for basic to moderate text processing needs. For advanced regex operations requiring capture groups, consider using the Run Code node with Python for full regex functionality.