Prompt Replace
Stop editing the same text in ten places
- prompt
Prompt Replace is a text find-and-replace node dressed as a ComfyUI widget: you feed it a prompt (or any string), give it up to three find/replace pairs, and it hands back the prompt with those swaps applied, in order. That's the whole thing, and it's one of those nodes you don't think you need until a workflow forces you to reuse the same prompt across a batch.
The payoff is that it turns text editing into a data operation instead of a manual one. Picture a batch workflow where a stored base prompt gets reused across runs: the base lives in one text box, and this node swaps in a different artist, character, or quality block per branch. You change one replace field and every downstream copy updates - no hunting through five CLIP Text Encode boxes to make sure you edited them all the same. It's the same "one source, many consumers" instinct that the whole plumbing layer runs on (see the comfyui-node-plumbing essay for why that instinct is worth trusting), applied to strings.
It also earns its keep for negative-prompt housekeeping. Keep a clean master negative and have this node strip or swap terms per workflow - remove an artist's name from the negative when you're testing that artist, downgrade a quality tag, de-duplicate. Anything you'd reach for Ctrl+H to do across a text file, this does at runtime.
How it works
Under the hood it's a sequence of plain Python str.replace() calls. The pairs are applied strictly in order - find1/replace1 first, then find2/replace2, then find3/replace3. Two details in the source matter:
- Empty
findfields are skipped. Iffind2is blank, that pair is ignored entirely. So you can leave slots unused without them doing anything weird. - It's literal substring replacement, applied everywhere.
str.replaceswaps every occurrence, and it doesn't respect word boundaries. Replace "art" and you'll also hit "artist," "cart," and "part." If you need regex or word-boundary matching, this isn't the node.
Because it's ordered, the pairs can chain: replace A with B, then replace B with C in the next slot. That's occasionally useful (careful with it - it's also how you accidentally produce C everywhere).
The inputs that matter
- prompt - the multiline input,
forceInput, so it takes a wire from a text node or another string processor. It's the only required field. - find1 / replace1, find2 / replace2, find3 / replace3 - three find-and-replace pairs, all optional. Leave a
findempty to skip that slot. - prompt (output) - the transformed string, ready for a CLIP Text Encode (positive or negative).
How to install it
Part of ComfyUI-Practical-Tools by wenchengxiang. ComfyUI Manager → search ComfyUI-Practical-Tools → install → restart, or:
cd ComfyUI/custom_nodes
git clone https://github.com/wenchengxiang/ComfyUI-Practical-Tools
No requirements beyond what ComfyUI already ships, and nothing to download.
Common issues
- Unintended substring hits. "Replace
realwithfake" will also rewrite "reality." Keep your find strings distinctive - longer, less-common tokens. - Order dependence. Since replacements apply in sequence, a find string produced by an earlier replacement can be caught by a later one. If your output looks wrong, check whether one pair is colliding with another.
- Nothing to feed it yet. The
promptinput is force-input, so it must come from a wire - a text primitve, a prompt book, another string node. You can't just type into it as a plain widget and have it work standalone.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| prompt | STRING | — | |
| find1opt | STRING | — | |
| replace1opt | STRING | — | |
| find2opt | STRING | — | |
| replace2opt | STRING | — | |
| find3opt | STRING | — | |
| replace3opt | STRING | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| prompt | STRING | — |