FB String Replace
Fix a dozen prompt typos with one node
- STRING
Prompt hygiene is the quiet tax of image generation. You keep typing masterpiece into every prompt when your model doesn't want it, or you've got a misspelled tag that's been in your workflow for a month, or you want to swap a LoRA trigger word across an entire prompt. FB String Replace is the batch find-and-replace node for exactly that: a list of "old" strings, a parallel list of "new" strings, one node, all of it replaced in one pass.
If you've ever stacked five ReplaceText nodes just to clean a prompt, you know why this one exists.
How it works
You feed in the text to fix via value (which is a force-input - you wire it from another node rather than typing), then two multiline boxes: olds with one pattern per line, and news with one replacement per line. Lines pair up by position: the first old gets replaced by the first new, second by second, and so on. If the line counts don't match, the node refuses to run and tells you exactly why.
olds: masterpiece, 8k, absurdres, old_trigger
news: , , , new_trigger
Each pair is applied in order to the evolving string. Two toggles shape the behavior:
- recursive (default on) - after a full pass, if the text changed at all, the node runs the whole pass again and keeps looping until nothing changes. This catches chains, like replacing
awithband thenbwithcin a follow-up pass. - use_regex (default off) - each "old" line is treated as a regular expression and replaced via
re.sub. Wildcards, alternation, capturing groups - the full regex toolbox, if you want it.
Inputs and outputs
- value - the input string (force-input, so wire it in).
- olds - multiline; one search pattern per line.
- news - multiline; one replacement per line, aligned with olds.
- recursive - whether to re-run passes until stable.
- use_regex - whether patterns are regex.
- STRING - the cleaned output.
Where people get burned
- "The number of old and new strings must be the same." The most common error, and it's self-explanatory when you see it. Count your lines.
- Line pairing. Old line 3 is replaced by new line 3. If a replacement lands in the wrong place, it's almost always misalignment - add a blank line to pad.
- Empty lines are real entries. An empty old line is a no-op replace; an empty new line deletes the old text. Both are occasionally useful, both confuse people when unintended.
- recursive on + self-referential patterns can chase its tail - if a run ever seems to hang, your olds/news are fighting each other. Flip recursive off and the single pass usually does what you meant anyway.
- Regex mode throws at runtime if a pattern is malformed. You'll see the error in the UI and console; it doesn't crash ComfyUI.
Install
Standard for this pack - no dependencies, no models:
cd ComfyUI/custom_nodes
git clone https://github.com/FredBill1/comfyui-fb-utils
Restart ComfyUI, look under the FredBill1 category (or ComfyUI Manager: search comfyui-fb-utils). The entire pack is Python standard library - no pip step, nothing that can clash with other nodes. The README is one line; if you want proof of how the replace loop behaves, the source is short and readable.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| value | STRING | — | |
| olds | STRING | — | |
| news | STRING | — | |
| recursive | BOOLEAN | true | — |
| use_regex | BOOLEAN | false | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| STRING | STRING | — |