Replace String
Regex find-and-replace on prompts and text
- STRING
Find-and-replace for text inside a workflow, powered by regex. You give it a string, a pattern to match, and what to swap in - and it hands back the edited string. It's the node you drop in when a prompt, a filename, or a caption needs a programmatic tweak instead of a manual edit.
The everyday cases are dull and useful: strip a word out of every prompt (ReplaceWith empty deletes matches), swap one trigger word for another across a batch, clean junk out of tagger output, normalize spacing or separators. Anywhere text flows through your graph and needs a consistent transformation, this handles it without you retyping.
The regex part is the catch
Read the input name carefully: it's Regex, not "find this literal text." The pattern is treated as a regular expression, which is powerful and also the thing that trips people up. If your pattern contains regex metacharacters - . ( ) [ ] * + ? | \ $ ^ - they have special meaning and won't match themselves literally. Trying to replace a literal 1.5 will also match 1x5 or 195 because . means "any character."
That's a feature when you want it - you can match "any number," "a word boundary," "one or more spaces" - and a footgun when you don't. If you just want a plain literal swap, escape the special characters (put a backslash before them) or keep your pattern to plain letters, digits, and spaces where nothing needs escaping.
The inputs
All three are required and all three are strings:
- String - the text to operate on.
- Regex - the pattern to find. Regex syntax, not literal.
- ReplaceWith - what to substitute in. Leave it empty to delete matches. If you used capture groups in the pattern, standard backreference syntax applies here.
The output is a single STRING - the transformed text - ready to wire into a prompt encoder, a save-text node, or a filename builder.
Installing ComfyUI-LogicUtils
ComfyUI Manager: Install Custom Nodes → search "ComfyUI-LogicUtils" → install → restart. Or:
cd ComfyUI/custom_nodes
git clone https://github.com/aria1th/ComfyUI-LogicUtils
Restart ComfyUI. Regex is in Python's standard library, so there's nothing extra to install.
Worth knowing
The pack is aria1th's (AngelBottomless) utility collection, undocumented on purpose. The single thing that will bite you here is forgetting the match field is a regex - if a replace "isn't working" or is replacing too much, that's almost always the cause. Test your pattern on a known string before turning it loose on a batch, and when in doubt, escape the punctuation.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| String | STRING | — | |
| Regex | STRING | — | |
| ReplaceWith | STRING | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| STRING | STRING | — |