ComfyUI Node

Replace Text _O

Find-and-replace for your prompts

By omar92·Created 3 years ago·Updated 5 months ago· 181
Replace Text _O
    • STRING
    text
    old
    new

    You've got a working prompt, and you want a variant without rewriting the whole thing: swap the subject, strip a tag, fix a typo that appears in ten places. Replace Text _O is the find-and-replace node for strings - give it text, an old substring, and a new replacement, and out comes the modified string.

    It's in the Quality of Life Suit's O/text/operations group, and it slots neatly into the pack's prompt-engineering story. Wire a base prompt into text, hook a ChatGPT-generated or manually typed old/new pair in from other text nodes, and you've got prompt variants you can build and swap without touching the main prompt string. Paired with QOL Split String and Concat Text _O, you can assemble, break apart, and rewrite prompt pieces entirely from wired nodes.

    How it works

    The mechanism is Python's str.replace() under the hood. Two things that behavior implies, and both will surprise you if you don't expect them:

    • It replaces all occurrences. If old appears five times, all five get replaced. There's no "first match only" option. Usually that's what you want (that's what makes it useful for cleaning up a repeated typo), but it means you can't surgically change one instance in a list of similar tags.
    • It's a literal substring match, case-sensitive. "flower" will not match "Flower". It's also not a regex, so "cat.*" is literally the characters c-a-t-.*, not a wildcard. If you need regular expressions, this isn't the node - reach for a Python-expression utility instead.

    One genuinely useful trick: replace with an empty string to delete a substring. Want to drop , watermark from every prompt in a batch? old=", watermark", new="". That's the closest this node gets to a "remove" button.

    The inputs that matter

    • text - the string to operate on (multiline).
    • old - the substring to find.
    • new - what to replace it with (empty is allowed and useful).

    Output: a single STRING.

    Installing

    cd ComfyUI/custom_nodes
    git clone https://github.com/omar92/ComfyUI-QualityOfLifeSuit_Omar92.git
    

    or ComfyUI Manager → search ComfyUI-QualityOfLifeSuit_Omar92, then restart ComfyUI. No dependencies.

    Gotchas

    Watch the empty-match edge case: if old is an empty string, str.replace("", x) inserts x between every character - almost never what you intended. And remember the ordering when you chain replacements: since each pass sees the output of the last, a replacement that itself contains old text will keep matching. For straightforward prompt editing, none of that will bother you - it just works.

    CategoryO/text/operations

    Inputs (3)

    NameTypeDefaultDescription
    textSTRING
    oldSTRING
    newSTRING

    Outputs (1)

    NameTypeDescription
    STRINGSTRING