String Replace
Find-and-replace for prompts, and the count trap
- result
String Replace is the find-and-replace you already know from every text editor, dropped into your graph. You feed it a string, tell it what to look for and what to swap in, and it hands back the edited result. The everyday use in a ComfyUI workflow is prompt cleanup: strip a tag you don't want, swap one character name for another, or normalize a messy string before it hits your CLIP Text Encode node.
Where it earns its keep is when your prompt text isn't a constant. If you're building prompts dynamically - string from a LoRA's trigger words, a tag list from a wildcard or style node - you can't just edit the text box. That's when a find-and-replace node becomes a real tool instead of a convenience. And because text encoders are famously picky about what you feed them, cleaning a prompt before encoding is a legitimate workflow step, not busywork.
Mechanically it's a thin wrapper around Python's str.replace(). That's also where both of its traps live.
The inputs, per the node's schema:
- text (required) - the string you're editing
- find (required) - the exact substring to look for
- replace (required) - what to put in its place
- count (optional, default -1) - how many occurrences to replace
The output is a single result string. The count input is the subtle one. The default is -1, which means "replace all occurrences" - that's almost always what you want, and leaving it alone is correct. But if you set it to a positive number, you're using Python's semantics, which count from the left: count=1 replaces only the first occurrence, not "the one that exists." If you expected it to error when there's no match, it doesn't - no match just means the string passes through unchanged.
The other trap is an empty find field. In Python, str.replace() with an empty search string doesn't do nothing - it inserts your replacement between every single character. Leave find blank by accident and "hello" becomes "XhXeXlXlXoX" (plus one on each end). It's a classic copy-paste-of-a-node mistake, and the symptom is obvious once you see it.
Also worth knowing: this is literal text replacement, not regex. If you need pattern matching like "remove everything between these two markers," this isn't the node - grab a regex-capable text node from a bigger pack instead. And there's no case-insensitive option, so "sdxl" won't touch "SDXL."
Install. It ships in the ComfyUI Utilitools pack. In ComfyUI Manager, search "ComfyUI Utilitools" (pack title: ComfyUI Utilitools Nodes), or clone it directly:
cd ComfyUI/custom_nodes
git clone https://github.com/aesethtics/ComfyUI-Utilitools
Then restart ComfyUI. No dependencies, no model files - the whole pack is standard-library Python, so there's nothing extra to download.
Typical setup: put this between your prompt text node and CLIP Text Encode, run find="photorealistic", replace="photo", leave count at -1, and every occurrence gets cleaned in one pass. It's simple, it's honest, and the only way it bites you is if you forget what count actually does.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| text | STRING | — | |
| find | STRING | — | |
| replace | STRING | — | |
| countopt | INT | -1-1–1000 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| result | STRING | — |