ComfyUI Node

replace

Find-and-replace in your prompt, and it's regex under the hood

By YMC-GitHub·Created 3 years ago·Updated about a year ago· 20
replace
    • text
    text
    find
    replace
    action

    "Replace" sounds like the most boring node imaginable, until you're swapping a checkpoint's trigger phrase across a hundred prompt lines. Replace does text find-and-replace on a string, with one twist that matters: the find field is treated as a regular expression, not a plain substring. That's both its power and its first trap.

    The practical use is prompt housekeeping: strip a stale artist tag, normalize score_9, score_9 noise, swap (masterpiece:1.2) for masterpiece, or rewrite a trigger word without touching the rest of the string. Because it's regex, you can also do structural edits - collapse doubled spaces, remove bracketed chunks, reorder with capture groups - that a plain replace can't touch.

    How it works

    It's a direct wrapper around re.sub(find, replace, text). Whatever you put in find is compiled as a regex pattern and substituted with replace across the whole string. The action dropdown (yes/no) is a master switch: set to no and the node returns the text untouched - handy for bypassing the replacement without deleting the node.

    The regex detail matters: find = "dress" replaces the literal word, but find = "." matches any character, and find = "cost$" anchors to the end. If you're replacing something with regex metacharacters (., *, +, (, ), [, ], |), you need to escape them or your "plain" replacement will do something wild. Most people hit this exactly once.

    Inputs and outputs

    • text - the input string
    • find - the regex pattern to search for
    • replace - the replacement text (regex backreferences like \1 work)
    • action - yes (do it) | no (pass through)
    • Output: text - the modified string

    Installing it

    # ComfyUI Manager: search "ymc suite" and install ymc-node-suite-comfyui
    # or:
    cd ComfyUI/custom_nodes
    git clone https://github.com/YMC-GitHub/ymc-node-suite-comfyui
    

    Restart after installing. Four tiny pure-Python PyPI helpers self-install; no models, no GPU cost.

    Gotchas

    • find is regex. Test on a small string via a show text node before you point it at a whole prompt library - a mistyped pattern can silently eat more text than you meant.
    • Replacement with backreferences (\1) works but is easy to fumble in a UI field; double-check the escaping.
    • The related prompt - add family does tag-aware editing (it splits on commas and understands (weight:1.2) syntax). If your target is a tag rather than arbitrary text, that family is often the safer tool - this node is the blunt instrument.
    • WAS-conflict note as with the rest of the pack: if WAS Node Suite is installed too, Manager may flag shared node names between the packs.
    Categoryymc suite/text/plain

    Inputs (4)

    NameTypeDefaultDescription
    textSTRING
    findSTRING
    replaceSTRING
    actionCOMBO2 options: yes, no

    Outputs (1)

    NameTypeDescription
    textSTRING