Text Batch Replace (FeiMao-326)
Up to 8 find-and-replace operations in one node — your prompt cleanup workhorse
- text
Every serious workflow ends up doing find-and-replace somewhere. An LLM spits out a prompt with curly quotes and the model wants straight ones. A batch of tags arrives with 1girl and you need 1girl, solo. Do that with five chained nodes and the graph looks like spaghetti. This node lets you stack up to eight find/replace pairs in one place and run them in sequence on whatever string you feed it.
How it works
One text input (multiline), then find_1 / replace_1 through find_8 / replace_8 - eight optional pairs. The node collects any pairs where find_n is filled in, sorts them by index, and applies each replacement to the text in order. A few implementation details are worth knowing:
- It's sequential and order-dependent. Pair 1 runs first, then pair 2 operates on the result of pair 1. That's usually what you want (fix punctuation, then replace words), but it also means pair 1's replacement text can itself be matched by pair 2. If you're replacing overlapping tokens, think about ordering.
- Replacement is a plain substring swap (
str.replace), not regex. No wildcards, no capture groups - if you need patterns, the pack's Regex Extractor Pro is the node for that. This one is blunt, literal, and predictable. - Empty find fields are skipped, so you can leave unused pairs blank without side effects.
- Pairs are processed by number regardless of fill order, which saves you from a confusing bug where pair 3's text got replaced before pair 1's because of dict iteration order.
The output is a single text string. Straight in, straight out.
Where it fits
The most common setup is a last-chance scrub before the KSampler: LLM-generated prompts arrive full of conversational debris, and one Text Batch Replace cleans them up in a single pass. It also shines at normalizing a vocabulary - think of it as the poor man's Dictionary Translator, but simpler because every pair is right there in the node and you don't have to format a JSON mapping.
Honest caveat: for 1–2 quick substitutions, a single Replace node from ComfyUI core is lighter. This pulls its weight the moment you're doing 4+ swaps, or when you want the whole cleanup policy visible in one place. Eight pairs is a decent cap; if you routinely need more, you're probably in prompt-engineering territory where a proper pipeline (LLM → cleaner → template) beats a mega-replace node anyway.
Inputs and outputs
text(STRING, multiline) - the input to transform.find_1…find_8/replace_1…replace_8(STRING) - the swap pairs, all optional.text(STRING) - the result.
Installing
This is one of the sixteen nodes in the FeiMao-326 pack, so install the pack once. ComfyUI Manager (search "Comfyui-General-API-Node") or:
cd ComfyUI/custom_nodes
git clone https://github.com/FeiMao-326/Comfyui-General-API-Node.git
cd Comfyui-General-API-Node
pip install -r requirements.txt
Restart ComfyUI afterward. It lives under Add Node → FeiMao-326 → Text Batch Replace, and shares the pack's light dependency set (openai, numpy, Pillow, requests) with no model downloads.
Inputs (17)
| Name | Type | Default | Description |
|---|---|---|---|
| text | STRING | — | |
| find_1opt | STRING | — | |
| replace_1opt | STRING | — | |
| find_2opt | STRING | — | |
| replace_2opt | STRING | — | |
| find_3opt | STRING | — | |
| replace_3opt | STRING | — | |
| find_4opt | STRING | — | |
| replace_4opt | STRING | — | |
| find_5opt | STRING | — | |
| replace_5opt | STRING | — | |
| find_6opt | STRING | — | |
| replace_6opt | STRING | — | |
| find_7opt | STRING | — | |
| replace_7opt | STRING | — | |
| find_8opt | STRING | — | |
| replace_8opt | STRING | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| text | STRING | — |