String Replace
Find-and-replace that hits every occurrence at once
- string
String Replace is the find-and-replace node: swap every occurrence of one substring for another, and hand back the cleaned result. It's the node you reach for when text arrives with cruft - boilerplate tags, wrong words, stray punctuation - and you want it gone or rewritten before the string goes anywhere important.
What it is
It runs Python's s.replace(to_replace, replace_with), and the thing to know cold is that it replaces every occurrence, not just the first. "a, b, c" with to_replace = ", " and replace_with = " " becomes "a b c" - every comma-space gets collapsed, not just one. That's usually what you want for cleanup, but it means you can't use this node to surgically swap just the first match.
The killer use case is prompt hygiene. LLM-generated prompts carry junk: a model that keeps inserting "masterpiece," in every sentence, or a source that adds (fast) weight syntax you don't want on your current encoder. Feed the text through String Replace with the offending phrase as to_replace and an empty replace_with and it's gone everywhere. (A note for 2026 models: the KB's prompt-engineering doc covers how attention-weight syntax like (word:1.3) is silently discarded on LLM-encoded models anyway - but if you're on SDXL-lineage, cleaning it before it hits the encoder is genuinely useful.)
The inputs and outputs
s(STRING) - the text to modify.to_replace(STRING) - the substring to find. If it isn't present, the string passes through unchanged.replace_with(STRING) - the substitution. An empty string deletes the match.string(STRING) - the result.
Three in, one out.
How to install it
Part of the string-util pack, a dependency-free repo like the rest:
cd ComfyUI/custom_nodes
git clone https://github.com/kale4eat/ComfyUI-string-util
or install "ComfyUI-string-util" via ComfyUI Manager and restart. It's under the string-util category.
Common issues
The all-occurrences behavior is the one that surprises people - if you expected a single, first-match replacement, this node will overshoot. Case sensitivity is the other: "masterpiece" won't match "Masterpiece", so chain a String Lower normalization if your junk might arrive in mixed case. And remember replacements are literal substring swaps, not regex - you can't use wildcard patterns here. For pattern matching, you'd need a different tool entirely; for plain cleanup, this is exactly right.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| s | STRING | — | |
| to_replace | STRING | — | |
| replace_with | STRING | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| string | STRING | — |