Nodes/ComfyUI-SaturnNodes/πŸͺ πŸ”€ Multi Text Replacer
ComfyUI Node

πŸͺ πŸ”€ Multi Text Replacer

One find-and-replace node for thirty terms β€” and why it won't eat its own output

By KOFibltoΒ·Created 2 months agoΒ·Updated 2 days agoΒ· 1
πŸͺ πŸ”€ Multi Text Replacer
    • text
    • replaced_count
    β—„findβ–Ί
    β—„replaceβ–Ί
    β—„case_sensitivefalseβ–Ί
    β—„search_modeComma Separated Listβ–Ί
    β—„textβ–Ί

    Prompt cleanup is death by a thousand small edits. You want masterpiece, best quality, ultra detailed gone from every prompt that passes through, you want girl swapped for woman on the fly, you want that one token you keep fat-fingering fixed. Doing it with six chained string-replace nodes works and looks terrible. This node takes a list of search terms, a list of replacements, and does the whole pass in one shot - then tells you how many hits it made.

    How it works, and the one detail that matters

    find is a list. In Comma Separated List mode it's parsed with a real CSV reader, so each line counts as a record and commas separate entries within a line. Practically that means both of these are valid inputs in the same box:

    masterpiece, best quality
    ultra detailed
    

    And if a term contains a comma, quote it - "1girl, solo" - otherwise it'll be split into two targets.

    Here's the part worth caring about. The node sorts your targets longest-first, escapes them, joins them into one alternation pattern, and does a single substitution pass across the text. That's deliberate: a naive loop over terms can replace something twice - you swap red for blue, then a later rule turns blue back into green - and you never notice until an image looks wrong. A single pass makes that impossible.

    Replaced count is the number of matches found before the substitution, so it reflects the original text, not any cascade.

    In Regex Pattern mode the parsing flips: one pattern per line, applied in order, each compiled independently. A bad pattern is skipped with a message in the console instead of killing the run.

    Inputs and outputs

    You set find (multiline), replace (single line), and optionally case_sensitive and search_mode, both tucked under advanced. The text to modify arrives on the optional text input - wire it from a CLIP Text Encode's text, a Prompt Counter, or a queue iterator.

    Two outputs: text, the modified string, and replaced_count, an INT. The count is more useful than it sounds for debugging - if a rule you know should fire reports zero, your phrasing is off, not your workflow.

    Two traps

    The replacement is literal. This isn't sed. \1 in the replace field inserts a literal backslash-one; there are no backreferences and no case transforms. If you need captured groups back in the output, you need a different node.

    List mode matches substrings, not words. Patterns are escaped but not word-bounded, so a target of cat will also hit concatenate. Two ways out: spell out the full phrase, or switch to Regex Pattern mode and write \bcat\b per line. Case-insensitive by default, which is usually what you want in prompts - but it also means a target of Ann eats every ann in sight.

    Install

    ComfyUI Manager β†’ search SaturnNodes, or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/KOFiblto/ComfyUI-SaturnNodes
    

    Restart. Pure Python string work - the pack's requirements.txt is Pillow, numpy and piexif, and this node uses none of them. It appears under πŸͺ SaturnNodes/Utils.

    Where it earns its place

    Put it after your prompt source and before the text encode. Wire the text output into positive conditioning and a second copy into the negative, with different rule sets, and your boilerplate becomes one place to edit. The count output into a note node gives you a live readout of what your pipeline is actually doing to the text - which is more than the chained-replace setup ever told you.

    CategoryπŸͺ SaturnNodes/Utils

    Inputs (5)

    NameTypeDefaultDescription
    findSTRINGβ€”
    replaceSTRINGβ€”
    case_sensitiveBOOLEANfalseβ€”
    search_modeCOMBOComma Separated List2 options: Comma Separated List, Regex Pattern
    textoptSTRINGβ€”

    Outputs (2)

    NameTypeDescription
    textSTRINGβ€”
    replaced_countINTβ€”