Nodes/ComfyUI-TinyBee/Search and Replace
ComfyUI Node

Search and Replace

Find-and-replace for prompts, with a case-matching party trick

By TinyBeeman·Created about a year ago·Updated about a month ago· 1
Search and Replace
    • output_string
    input_string
    search_string
    replace_string
    case_sensitivecase sensitive

    You'll hit the "I need to swap one word everywhere in this prompt" problem within your first week of ComfyUI. You could hand-edit a text box, or you could wire up Search and Replace and let the graph do it. It's a straightforward global find-and-replace on any string, and it has one option that's actually a cut above what you'd expect from a utility node.

    How it works

    Four inputs, one output. You give it an input_string (a multiline box, so whole prompts fit), a search_string, a replace_string, and a case_sensitive dropdown with three choices. It outputs output_string - feed that into a CLIP Text Encode for the sampler, or into a Show Text node to check your work.

    The three case modes behave differently, which is worth knowing:

    • case sensitive - a plain literal replace. CatDog, and cat stays cat. The default.
    • case insensitive - matches the search text anywhere regardless of case, replacing with the literal replace_string.
    • match case - this is the sleeper feature. It matches case-insensitively, then adjusts the replacement to match the found text's casing. Found all-lowercase? Replacement comes out lowercase. Found ALL CAPS? Replacement is uppercased. Found Title Case? Replacement gets capitalized.

    That third mode is gold for cleaning up model names or artist tags where you don't know whether the incoming text says sdxl, SDXL, or Sdxl. One node handles all of them.

    The details that matter

    All matches are replaced, not just the first - it's a global replace. And if search_string is empty, the node returns the input untouched instead of erroring, which is a nice bit of defensive design when you're building a workflow where that field starts blank.

    Where you'd use it

    Prompt hygiene, mostly: strip a banned token out of every prompt in a batch, rename a tag consistently before it hits a LoRA trigger, or normalize text coming out of a captioning model. It also plays nicely with the rest of the TinyBee string set - pair it with Search To Boolean if you want to conditionally replace, or chain two Search and Replace nodes to do a multi-step cleanup.

    Install

    This is one node out of the ComfyUI-TinyBee pack. ComfyUI Manager: search ComfyUI-TinyBee, install, restart. Or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/TinyBeeman/ComfyUI-TinyBee
    

    Restart ComfyUI and the node appears under 🐝TinyBee/Strings. No models, no Python dependencies beyond the standard library for this node - the pack's pillow/jsonata requirements back its image and JSON nodes, not the string ones.

    Gotchas

    The only real trap is assuming the plain replace is case-insensitive when the dropdown says otherwise. It defaults to case sensitive, so if your search doesn't match anything, the string comes back identical and you'll stare at it wondering what broke. Bump it to "case insensitive" or "match case" first.

    Category🐝TinyBee/Strings

    Inputs (4)

    NameTypeDefaultDescription
    input_stringSTRING
    search_stringSTRING
    replace_stringSTRING
    case_sensitiveCOMBOcase sensitive3 options: case sensitive, case insensitive, match case

    Outputs (1)

    NameTypeDescription
    output_stringSTRING