Nodes/ULTools for ComfyUI/TextFindAndReplaceAdv
ComfyUI Node

TextFindAndReplaceAdv

Swap words in your prompt without regex headaches

By jkrauss82·Created 3 years ago·Updated a day ago· 9
TextFindAndReplaceAdv
    • result_text
    • replacement_count_number
    • replacement_count_float
    • replacement_count_int
    text
    find
    replace
    max_count0

    The most boring node in this pack is also one of the more useful. TextFindAndReplaceAdv takes a string, swaps one substring for another, and hands the result back. If that sounds like a text editor you already own, you're missing the point - the swap happens inside the graph, on the wire, between other nodes. That's what makes it the tool for prompt templating: one shared positive prompt that swaps a subject per run, a cleaned-up tag list, "replace 1girl with boy" as an actual workflow step instead of a copy-paste ritual.

    It's a trimmed fork of WAS Node Suite's Search and Replace. WAS is the old 210-node suite that went dormant years ago, and this is one of the operations that quietly kept living on elsewhere. Which brings up the one funny thing about it: the node's own description advertises "regex support," but the code regex-escapes your find text before matching. That means literal matching with no escaping needed. Special characters like (, :, ., [ just work - type 1girl, (flower:1.2) into find and it matches that exact text. It's the friendlier behavior in practice, even if the label oversells it.

    The inputs are straightforward:

    • text - the source string. It's force-input, so you must wire it in: right-click a prompt or string box, "Convert to input," and drop a text/primitive node into the socket.
    • find / replace - the substring and its replacement. The code will split either field on newlines and apply pairs in order (reusing the last entry if the lists differ in length), but the fields ship as single-line widgets, so in practice it's one pair at a time.
    • max_count - how many replacements to allow, default 0 meaning replace all. Set it to 1 and only the first occurrence in a tag list changes.

    Outputs are result_text plus the total replacement count duplicated as NUMBER, FLOAT and INT - three ports carrying the same number so you can feed whichever numeric socket your logic happens to need (a ShowText node, a switch, a condition that only fires when something was actually replaced).

    Two traps are worth knowing before you wire it into a workflow you care about. First, find defaults to empty - and an empty find matches everywhere, so the node will inject your replacement text between every character of the input. If you're not replacing anything, bypass the node rather than leaving find blank. Second, the replacement string goes through Python's regex engine raw, so a lone backslash in replace (say, a Windows path) throws a "bad escape" error. Keep replacements plain text and you'll never hit it.

    Install is the same pack for all three of these pages: ComfyUI Manager search for "ULTools", or git clone https://github.com/jkrauss82/ultools-comfyui into ComfyUI/custom_nodes, then pip install -r requirements.txt and restart. Unlike the kornia trio (Clahe, Histogram, UnsharpMask), this node is pure stdlib re - no extra dependency, no missing-import drama - so it's the one member of the pack most likely to Just Work on a fresh install. It lives under the utils category.

    I keep it in workflows not because it's clever, but because having prompt edits on the wire means I stop editing the same text in five places by hand. That alone is worth the five minutes it takes to add.

    Categoryutils

    Inputs (4)

    NameTypeDefaultDescription
    textSTRING
    findSTRING
    replaceSTRING
    max_countINT00–1000000

    Outputs (4)

    NameTypeDescription
    result_textSTRING
    replacement_count_numberNUMBER
    replacement_count_floatFLOAT
    replacement_count_intINT