Nodes/Comfyui-General-API-Node/Text Batch Replace (FeiMao-326)
ComfyUI Node

Text Batch Replace (FeiMao-326)

Up to 8 find-and-replace operations in one node — your prompt cleanup workhorse

By FeiMao-326·Created 12 months ago·Updated 5 months ago· 0
Text Batch Replace (FeiMao-326)
    • text
    text
    find_1
    replace_1
    find_2
    replace_2
    find_3
    replace_3
    find_4
    replace_4
    find_5
    replace_5
    find_6
    replace_6
    find_7
    replace_7
    find_8
    replace_8

    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_1find_8 / replace_1replace_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.

    CategoryFeiMao-326

    Inputs (17)

    NameTypeDefaultDescription
    textSTRING
    find_1optSTRING
    replace_1optSTRING
    find_2optSTRING
    replace_2optSTRING
    find_3optSTRING
    replace_3optSTRING
    find_4optSTRING
    replace_4optSTRING
    find_5optSTRING
    replace_5optSTRING
    find_6optSTRING
    replace_6optSTRING
    find_7optSTRING
    replace_7optSTRING
    find_8optSTRING
    replace_8optSTRING

    Outputs (1)

    NameTypeDescription
    textSTRING