Nodes/ComfyUI-YCNodes/YC text replace
ComfyUI Node

YC text replace

Find-and-replace for your prompt, up to three swaps deep — dead simple, occasionally perfect

By yichengup·Created 2 years ago·Updated 4 months ago· 48
YC text replace
    • prompt
    prompt
    find1
    replace1
    find2
    replace2
    find3
    replace3

    Feed it a prompt, give it up to three find/replace pairs, get the edited prompt back. It's Python's str.replace with a face - the whole implementation is three sequential .replace() calls. There's no regex, no wildcards, no case-insensitive magic. That's the whole node, and honestly that's most of what you need from a prompt-editing utility.

    What it's actually for

    Prompt reuse and programmatic swaps. You keep one template prompt and swap tokens per run: swap the subject, swap the style keyword, swap a quality tag. Or you're piping prompts in from a file/CSV and need to normalize them before they hit the CLIP encoder - strip a tag, replace a phrase that breaks your model, rename a trigger word. Anywhere you'd reach for find-and-replace in a text editor, this node does it inside the graph, live, per run.

    How it works

    Sequential replacement, in order: find1replace1, then find2replace2, then find3replace3. Because they run in sequence, you can do staged edits - replace one phrase, then operate on the result. Empty find fields are skipped cleanly (.replace("", ...) is a no-op in this setup since the node guards them with defaults). The replacements are case-sensitive and literal: "cat" will not match "Cat", and "cat" will match the "cat" inside "concatenate" - substring replacement, not whole-word.

    Inputs and outputs

    The inputs you'll actually set:

    • prompt - the text to edit (multiline)
    • find1 / replace1 - first swap
    • find2 / replace2 - second swap
    • find3 / replace3 - third swap

    Output is the edited prompt string, ready to wire into a CLIP Text Encode or a text display.

    Install

    Part of ComfyUI-YCNodes. ComfyUI Manager → search "ComfyUI-YCNodes" → install, restart, or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/yichengup/ComfyUI-YCNodes
    

    Deps are the pack standard (torch, numpy, pillow, opencv-python, scipy), no model files.

    Where people get burned

    • Substring, not word. "an""a" will happily rewrite "another" into "aother". Watch for short, common find strings; the node does exactly what you said, not what you meant.
    • Case-sensitive only. There's no ignore-case toggle. If your template mixes capitalization, you'll need exact-case matches or multiple pairs.
    • Three pairs max. More complex rewrites need a regex node or a Python-based text utility. This one is intentionally dumb.

    It's the node equivalent of a pocket knife: unglamorous, limited, and exactly right when the job is "swap a few tokens in this prompt before it goes to the encoder."

    CategoryYCNode/Text

    Inputs (7)

    NameTypeDefaultDescription
    promptSTRING
    find1optSTRING
    replace1optSTRING
    find2optSTRING
    replace2optSTRING
    find3optSTRING
    replace3optSTRING

    Outputs (1)

    NameTypeDescription
    promptSTRING