Nodes/comfyui-moonpack/Simple String Replace
ComfyUI Node

Simple String Replace

Find-and-replace for prompts, with the malformed lines actually reported

By moonwhaler·Created about a year ago·Updated 11 days ago· 16
Simple String Replace
    • text
    • ignored_lines
    text
    find_replace_pairsfind => replace old => new
    whole_word_matchfalse

    Plain find-and-replace on a string is a boring capability, and that's exactly why you want a node that does it without surprises. Simple String Replace takes text plus a list of find => replace pairs and applies them in order, so you can normalize a prompt in one pass: swap "girl" for "woman", strip a style tag, turn " hi res " into " 8k". The output is a clean string your CLIP encoder can actually use.

    The detail that separates this from a hand-rolled string hack is honesty about failure. When a line in your pairs list is malformed - missing the =>, or with an empty find side - the node doesn't silently drop it. It collects those lines and hands them back on a second output called ignored_lines. You always know what didn't apply, instead of discovering it three images later when your replacement mysteriously never happened.

    The inputs and outputs that matter

    • text - the source string.
    • find_replace_pairs - a multiline text box, one pair per line in find => replace format. The defaults (find => replace, old => new) make the syntax obvious. Empty replacement removes text, so remove_this => deletes it. Lines starting with # are treated as comments and skipped.
    • whole_word_match - the optional toggle worth knowing. Off, and it's a plain substring replace (so cat matches inside concatenate). On, it uses regex \b word boundaries and only matches complete words.
    • Outputs: text (the result) and ignored_lines (the malformed lines, newline-joined, empty when everything parsed).

    The detail that trips people

    Replacements apply sequentially, top to bottom, and later pairs operate on earlier results. That's a feature when you want chains (A => B, then B => C, so A becomes C) and a gotcha when you expect parallel, independent swaps. If two finds overlap, the second line sees the output of the first. Read your pairs top-down and order them deliberately.

    The other quirk: it's a literal, plain-string replace by default - no regex magic. That's on purpose (the pack's Regex String Replace exists for patterns), but it means find is matched as-is. Escape nothing, expect nothing fancy.

    Installing it

    Standard MoonPack install:

    cd ComfyUI/custom_nodes
    git clone https://github.com/moonwhaler/comfyui-moonpack.git
    

    or ComfyUI Manager → MoonPack → install, restart. Under MoonPack/string. No models, no third-party Python dependencies.

    Verdict

    For cleaning up prompts and normalizing text before it hits the encoder, this is a solid, no-frills pick - and ignored_lines is the kind of diagnostic touch that tells you the author actually used these nodes. If your replacements need real pattern matching, reach for Regex String Replace instead; for everything else, this one just works.

    CategoryMoonPack/string

    Inputs (3)

    NameTypeDefaultDescription
    textSTRINGSource text.
    find_replace_pairsSTRINGfind => replace old => newOne pair per line in 'find => replace' format. Empty replacement removes text.
    whole_word_matchoptBOOLEANfalseIf true, only complete words match (uses regex \b boundaries).

    Outputs (2)

    NameTypeDescription
    textSTRING
    ignored_linesSTRING