String Replace
Find and replace text in a string
- STRING
Find-and-replace, as a node. You give it a source string, tell it what text to look for, and what to swap in, and it hands back the string with every match replaced. str.replace() if you speak Python; the "Replace All" button if you speak word processor.
In a ComfyUI graph this is text-wrangling glue. Swap a placeholder token in a prompt template for a real value, strip a character out of a string (replace it with nothing), normalize separators, fix up a path, clean junk out of text before you parse it into a number. Any workflow that builds prompts or filenames dynamically ends up wanting a replace somewhere.
How it works
It replaces every occurrence of the target substring with the replacement, left to right, and returns the new string. It's a literal text match - case-sensitive, no wildcards or regular expressions.
Inputs and outputs
- source - the string to operate on.
- to_replace - the substring to find.
- replace_with - what to put in its place. Leave this empty to delete the matched text entirely.
Output is a single STRING with the replacements applied.
Installing it
Part of the pack's comfyui_primitive_ops file. Install via ComfyUI Manager (search Various ComfyUI Nodes by Type / comfyui-various) or clone:
cd ComfyUI/custom_nodes
git clone https://github.com/jamesWalker55/comfyui-various
Restart ComfyUI. No models, no extra dependencies.
Common issues
A few predictable snags:
- It's case-sensitive. Replacing
catwon't touchCatorCAT. If casing varies, that's a real limitation here - you'd need to normalize case first or run multiple replaces. - It replaces every match, not just the first. Usually what you want, but if a substring appears in places you didn't mean to touch, you'll change those too. Make your
to_replacespecific enough to only hit what you intend. - No regex. This is plain literal matching - no patterns, no wildcards. For simple swaps that's fine; for anything pattern-based you're reaching for the wrong node.
- Empty
to_replaceis a degenerate case - there's nothing meaningful to find - so give it an actual substring to look for.
The delete trick is the handy one people miss: set replace_with to an empty string and the node becomes a "remove this text" tool, great for stripping unwanted characters out of a value before parsing it.
If the node comes up red as missing in a downloaded workflow, the pack isn't installed - Manager's "Install Missing Custom Nodes" or a clone of the repo fixes it.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| source | STRING | — | |
| to_replace | STRING | — | |
| replace_with | STRING | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| STRING | STRING | — |