Replace Text
Literal find-and-replace, no regex involved
- STRING
Replace Text (StringReplace) is the boring, safe, reliable version of find-and-replace: swap every occurrence of one literal string for another, no patterns, no flags, no surprises. It's the node you reach for when you know exactly what you're looking for - "replace every 'masterpiece' with 'best quality'" - and you don't want regex in the room deciding what counts.
Don't let the "replace" name confuse you across the family, because ComfyUI core ships three similar nodes and they are not interchangeable. Replace Text (this one, StringReplace) is the literal version. Replace Text (Regex) (RegexReplace) is the pattern version. And there's an older, deprecated node also called "Replace Text (DEPRECATED)" (ReplaceText) from the dataset tooling - different class, marked dead. When a fresh workflow or a tutorial says "use Replace Text," this new core node is the one they mean.
How it works
The mechanism is a single Python str.replace(find, replace) call. Every occurrence of find in the input string becomes replace, done in one pass. Three behaviors fall out of that:
- It replaces all occurrences. No count option, no "first match only." If
findappears ten times, all ten get swapped. If you need only the first, you're in regex territory. - It's literal.
findis matched as plain text - a period matches a period, a*matches a*. There's no escaping, no metacharacters, nothing to double-check. This is the node's entire superpower. - Empty
findis a no-op. Searching for""and replacing with something - that's an "insert everywhere" trick that Python's replace explicitly doesn't do; it just returns the string unchanged. No crash, just nothing, which is honestly the friendlier outcome.
Inputs are three multiline text fields: string (what to process), find (what to look for), and replace (what to swap in). Output is a single STRING with the substitutions applied.
When to use it (and when not to)
Use it for prompt cleanup: standardizing a spelling across a generated prompt, swapping a style keyword, replacing a model's trigger phrase. Use it as the safe building block in a chain of text utilities - it's deterministic, so it's the one you trust inside an automated pipeline where a misbehaving regex would silently corrupt output.
Skip it when your text is variable. If the thing you're hunting could be "anything in parentheses" or "any number of trailing spaces," the literal version can't see it - that's RegexReplace's job, at the cost of thinking about escaping and flags. The rule of thumb: literal known text → this node, pattern-ish unknown text → RegexReplace. You'll use both, and now you'll know which is which without the "(DEPRECATED)" landmine in the middle.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| string | STRING | — | |
| find | STRING | — | |
| replace | STRING | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| STRING | STRING | — |