Nodes/RF Nodes/Replace text
ComfyUI Node

Replace text

Find-and-replace for your prompts — the poor man's dynamic text

By foxtrot-roger·Created 3 years ago·Updated 2 years ago· 2
Replace text
    • text
    textTemplate {text} to replace!
    search{text}
    replacevalue

    You've got a template prompt and one word that needs to change. Not a whole rewrite - just swap {subject} for an actual subject, or swap a model name out of a filename string. That's what Replace text (RF_TextReplace) is for: a plain, no-frills find-and-replace that runs Python's str.replace() over a block of text and hands you the result. It's the smallest building block of a dynamic-prompt workflow, and sometimes that's exactly all you need.

    It's easy to overlook because the defaults are a placeholder demo - the text field literally starts as Template {text} to replace!, searching for {text} and replacing with value. Change those to something real and it behaves. This is a node you'll typically wire, not type into: the text input is forceInput, so it expects a string arriving from another node.

    The inputs that matter

    • text - the source string, multiline. This is what gets searched.
    • search - the exact substring to look for (default {text}). Case-sensitive, plain string, no regex.
    • replace - the substring that replaces every match (default value), multiline so you can swap in a longer phrase.

    Output: text - the result string.

    The three traps

    • It replaces every occurrence. str.replace() hits all of them. If your template mentions {subject} twice, both get swapped. There's no "first match only" mode - if you need that, this isn't the node.
    • It's case-sensitive and exact. photo won't match Photo. If your replacement silently "doesn't happen," check casing first - this is the #1 "why did nothing change" moment, because the node won't error, it just returns the input untouched when there's no match.
    • No regex. If you're reaching for character classes or wildcards, you're past this node's job description. It's find-and-replace, full stop.

    Where it shines

    Token-based prompt templates. Keep a master string like watercolor of {subject}, soft light, pastel palette, wire a subject in via a text node, and replace {subject} with the real thing. Change the subject once and every branch of the workflow updates. You can also chain it: replace one token, then a second Replace node for another. It's not elegant, but it's dead simple to debug - everything it does is visible in the inputs and the output.

    Installing RF Nodes

    Zero dependencies, no model downloads. Via ComfyUI Manager search "RF Nodes", or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/foxtrot-roger/comfyui-rf-nodes
    

    Restart ComfyUI; the node sits under RF in the menu. If a downloaded workflow complains it's missing, that's the install step you skipped - the ecosystem's most common failure is exactly this (a workflow referencing nodes you don't have).

    CategoryRF

    Inputs (3)

    NameTypeDefaultDescription
    textSTRINGTemplate {text} to replace!
    searchSTRING{text}
    replaceSTRINGvalue

    Outputs (1)

    NameTypeDescription
    textSTRING