Nodes/ComfyUI-MDSNodes/String Replace
ComfyUI Node

String Replace

Patch a prompt mid-wire without retyping it

By MarwanDSAI·Created 3 months ago·Updated about 15 hours ago· 3
String Replace
    • STRING
    ◄string—►
    ◄search►
    ◄replace►

    Most of the work in a ComfyUI graph is wiring, and most of the annoyance is text. You have a prompt in one place and you need a slightly different version of it in another - the style word pulled out, a trigger token swapped, an unwanted phrase deleted before the prompt reaches a second encoder - and your options are to retype the whole thing into a second box (then keep the two in sync by hand, forever) or to find a node that does string surgery on a wire.

    String Replace is the second option at the smallest possible size: one needle, one replacement, one output.

    What it actually does

    The implementation is three lines and the consequences of those three lines are the whole article. It casts whatever arrives to a Python string, then - only if the search box is not empty - calls str.replace(search, replace). That means:

    • Literal, not regex. No \b, no groups, no .*. If your search box contains \d+ it will look for the characters backslash-d-plus.
    • Case-sensitive. Photo will not find photo.
    • Every occurrence goes, not the first. The "Single" in the name means one rule, not one match. Swap masterpiece out of a prompt and it leaves the building entirely.
    • An empty search box is a safe no-op. The input passes through untouched.

    That guard is a nicer failure mode than it sounds: a half-configured node degrades to a pass-through instead of shredding your prompt.

    The inputs that matter

    Three inputs, one output, and one gotcha.

    string is the text to modify, and it is declared as a forced input - meaning it renders as a socket with no text box. You cannot type into it. That's the thing people file bugs about, and it's by design: this node expects the string to come from somewhere else. Wire it from a CLIP Text Encode whose text widget you converted to an input, from the pack's own Text (Multiline) Dual, or from a core PrimitiveString. Leave it unconnected and the node simply won't run.

    search and replace are ordinary single-line widgets - fine for trigger-word surgery. If you need a needle containing newlines, right-click search → Convert widget to input and feed it from a multiline text node.

    The single output is a STRING named STRING - the final text after replacement - and it wires into anything that eats a string: a text-encode input, a filename builder, a note node, another replace.

    Where it earns its place

    The honest use case is one authoritative prompt, several downstream variants: one copy goes to the encoder as-is, another has the style suffix stripped first, a third has a trigger token swapped for a different LoRA. Without this you end up with three near-identical text boxes and no memory of which one you edited last.

    It's also the cheap way to A/B one word across a queue: expose replace as an input and feed it different substitutions between runs.

    The pack ships a String Replace (Multiple) sibling if you need a chain of rules rather than one. If you need regex or conditional logic, neither of them is what you want - that's rgthree's Power Puter territory, or a small Python node of your own.

    Installing it

    ComfyUI Manager is the normal route: search ComfyUI-MDSNodes (publisher marwandsai) and click install. Manually:

    cd ComfyUI/custom_nodes
    git clone https://github.com/MarwanDSAI/comfyui-mdsnodes
    

    Then restart ComfyUI and hard-refresh the browser tab. The node shows up in the add-node menu under MDSNodes → text, listed as "String Replace".

    Nothing else to install: the pack's requirements.txt is a single blank line, its pyproject.toml declares no dependencies, and there are no models to download or anything to compile. MIT licensed, version 1.8.0.

    One calibration note: this is one person's utility drawer, built to support his own "Ultimate Model Tester" workflow on Civitai, not a community project. A search of the big ComfyUI subreddits turns up no discussion of the pack or the author at all. Not a red flag - the code is clean, MIT, and three lines long - but there's no tutorial to fall back on. Read the tooltip and you know everything it will ever do.

    Common issues

    The string field won't accept typing. Correct, it's a forced input socket. Wire something into it.

    The node doesn't appear after installing. Restart the ComfyUI process, not just the browser tab. Custom nodes are imported at startup, and a fresh clone is invisible until then.

    Output is identical to input. Your search box is empty, or the case doesn't match, or the phrase you targeted only exists in the other prompt. The node reports no error for any of these - it just does nothing.

    You wanted to strip a whole class of things. It can't. Literal only - that's what rgthree's Power Puter or a scrap of Python is for.

    CategoryMDSNodes/text

    Inputs (3)

    NameTypeDefaultDescription
    stringSTRINGThe text block to be modified.
    searchSTRING—
    replaceSTRING—

    Outputs (1)

    NameTypeDescription
    STRINGSTRINGThe final string after the replacement has been applied.