Replace String
Regex Search-and-Replace for Your Prompts
- string
What it is
Replace String is the text-editor find-and-replace, as a ComfyUI node, with regular expressions thrown in. You feed it a string, a regex pattern, and a replacement, and it returns the processed text. It exists because prompts are strings, and strings are only ever one awkward join away from needing surgery.
The one-line use case: strip a tag you don't want, fix a token that's breaking your prompt, or clean up text that came out of an LLM or a captioner before it hits your encoder. It's small, it's predictable, and sometimes that's exactly the tool you need.
How it works
The engine is Python's re.sub, applied to your input string. Whatever matches your Regex pattern gets replaced by ReplaceWith. After the regex pass, it also collapses any line breaks into spaces - that's a deliberate touch for prompt output, since a prompt with embedded newlines often gets mangled downstream. One string in, one string out.
That's the whole mechanism. There's no special syntax beyond standard Python regex - if you know re.sub, you know this node. The reason it's worth having as a node rather than a bash one-liner is that it's live in your graph: you can chain it after a prompt generator, before a text encoder, and tweak the pattern without rebuilding anything.
The inputs and outputs that matter
- String - the input text to process.
- Regex - the pattern to match. Empty pattern = no replacement happens, so an accidental blank here just passes text through.
- ReplaceWith - what matches get replaced with. Can be empty to delete matches entirely.
Output:
- string - the processed text, newlines collapsed to spaces.
When you'd use it
Wherever a prompt needs light surgery. Common cases: dropping a trigger word you don't want, removing "artist name" from a batch of captions, normalizing spaces or underscores in tags, or cleaning the stray formatting that an LLM prompt-expander leaves behind. If your need is heavier - pattern-based removal of whole categories of content, age adjustment, NSFW handling - the sibling Replace String Advanced (v3) node in the same pack is the one that does more than this. This node is the blunt instrument; use it when blunt is enough.
Installing it
Ships with ComfyUI_Eclipse:
cd ComfyUI/custom_nodes
git clone https://github.com/r-vage/ComfyUI_Eclipse
pip install -r ComfyUI_Eclipse/requirements.txt
then restart, or use Manager and search "Eclipse". If you're loading old graphs, remember the pack (formerly RvTools_v2) removed legacy nodes in v4.0.0 - the bundled migration tool sorts that out.
Common issues
The classic footgun is regex you didn't intend to write. A pattern like c matches every "c" in the string, not the word "c" - anchor your patterns (\bc\b for whole words) or you'll shred your prompt. And if replacements aren't happening, check case: the node is case-sensitive, so ANIME won't match anime. For case-insensitive matching, you're better off in the v3 node or writing (?i) into the pattern yourself.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| String | STRING | Input string to process. | |
| Regex | STRING | Regular expression pattern to match. | |
| ReplaceWith | STRING | Replacement string for matches. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| string | STRING | β |