Nodes/comfyUI-tool-2lab/replace text 替换文本
ComfyUI Node

replace text 替换文本

Find-and-replace for your prompts (and any other string that annoys you)

By AI2lab·Created 2 years ago·Updated 2 years ago· 23
replace text 替换文本
    • text
    text
    old
    new

    Most people find this node the same way: they have a workflow that generates a prompt somewhere upstream, they want to swap one word for another, and they google "replace text ComfyUI". That's exactly what replace_text (2lab) is - a plain, no-frills find-and-replace for strings. No model, no API, no key, no file loading. It's the text equivalent of a hammer: you'll grab it more often than you expect.

    Why it earns a slot in a graph: ComfyUI's core nodes give you lots of ways to write strings, but almost none to edit them. When an LLM node spits out a prompt, or you've got a big list of saved prompts you want to clean up in bulk, you usually end up hand-editing widget text or reaching for a big utility pack. This node is the small, boring solution. Wire it between whatever produces text and whatever consumes it, and you can swap a character name, replace a style tag with a different one, delete a token by replacing it with nothing, or fix a typo that's baked into a generated list.

    How it works

    Three strings in, one string out, in the most literal sense you can imagine.

    • text - the full string you want to edit. It's a multiline box, so whole paragraphs and entire prompts fit fine.
    • old - the substring to find.
    • new - what to replace it with. Leave this empty and you've got a delete function.

    The text output is the edited result, ready to plug into whatever downstream node needs a STRING - typically a CLIP Text Encode or another LLM call.

    The semantics are straightforward substring replacement, so two things to keep in mind. It's case-sensitive: old: "cyberpunk" will not touch "Cyberpunk". And if old doesn't appear in the text at all, you don't get an error - you get the original string back unchanged. That silent pass-through is the thing that burns people; if a prompt swap "isn't working," first check whether the string you're replacing actually appears in the input.

    Installing it

    The node ships in the AI2lab/comfyUI-tool-2lab pack. Easiest path: ComfyUI Manager → Custom Nodes Manager → search comfyUI-tool-2lab → Install → restart ComfyUI. Or do it by hand:

    cd ComfyUI/custom_nodes
    git clone https://github.com/AI2lab/comfyUI-tool-2lab
    

    Then restart ComfyUI. The pack is a Chinese developer's grab-bag of small utilities - every node name carries a 中文 label, and the README is literally one word ("toolkits"), so the nodes are the documentation. No model downloads, no heavy Python dependencies, no requirements.txt drama. It's one of those packs where nothing is glamorous and everything just works - if you're doing prompt automation at all, the thirty seconds it takes to install it pays for itself the first time you don't have to hand-edit a hundred prompts.

    Category🦊2lab/util/text

    Inputs (3)

    NameTypeDefaultDescription
    textSTRING
    oldSTRING
    newSTRING

    Outputs (1)

    NameTypeDescription
    textSTRING