Nodes/ComfyUI-iTools/Text Replacer
ComfyUI Node

Text Replacer

The boring node that powers prompt variation workflows

By MohammadAboulEla·Created 2 years ago·Updated 27 days ago· 237
Text Replacer
    • text_out
    text_in
    match
    replace

    The most useful node in your graph is often the dumbest one. Text Replacer from iTools does exactly one thing: it finds a substring in some text and replaces it. Under the hood it's literally Python's str.replace - no regex, no modes, no surprises. And that plainness is the feature, because it's the foundation of one of the handiest prompt tricks in ComfyUI.

    The combo that makes it worth having

    The README's example is the one you'll actually use. Take a list of prompt lines in a line loader, load them one by one (or randomized), run each through Text Replacer to swap the subject or style keyword, and one base prompt turns into a batch of variations. Two lists of five elements give you 25 possible outputs; three lists get you 125. That's how you run a cheap prompt grid without hand-writing every line - it pairs nicely with dynamic prompt loops, and iTools packs actually show up in real workflow shares for exactly this kind of prompt rotation.

    Since the node is a pure string pass-through, you can chain Text Replacers to swap several things at once, or wire its output into the next node and let the batch run.

    Inputs and outputs

    Three inputs, one output - this is as small as a node gets:

    • text_in (STRING) - the text to modify. Forced as an input, so wire it from upstream.
    • match (STRING) - the literal substring to find.
    • replace (STRING) - what to swap it with.
    • Output: text_out (STRING) - the edited text, ready for a CLIPTextEncode or the next transform.

    Install

    It's part of the iTools pack. ComfyUI Manager: search ComfyUI-iTools, install, restart. Or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/MohammadAboulEla/ComfyUI-iTools
    

    No requirements.txt, no model downloads, nothing heavy - the whole pack is JavaScript plus small Python nodes. Look for it under the iTools category.

    Where people get burned

    The one thing to know: str.replace replaces every occurrence of match, not just the first. If you only want the first hit replaced, you need a regex node (the same pack's Regex Editor can do it with the right pattern). The flip side is that this is a literal find-and-replace, which makes it the right tool when your match contains regex-meaningful characters - like the (word:1.3) emphasis weighting in SD prompts. Feed those parentheses to a regex node and they get treated as groups; Text Replacer just finds them as text and swaps them. That's not a bug, it's the reason this node exists.

    One more: replace with an empty string deletes the match entirely, which is occasionally what you want - worth knowing so a "blank" mistake doesn't look like the node eating your text.

    CategoryiTools

    Inputs (3)

    NameTypeDefaultDescription
    text_inSTRING
    matchSTRING
    replaceSTRING

    Outputs (1)

    NameTypeDescription
    text_outSTRING