Nodes/ComfyUI_EmAySee_CustomNodes/EmAySee Text Replace 20
ComfyUI Node

EmAySee Text Replace 20

Twenty find-and-replace pairs in one node, applied in order

By EmAySee·Created about a year ago·Updated 5 months ago· 3
EmAySee Text Replace 20
    • STRING
    ◄text—►
    ◄find_1►
    ◄replace_1►
    ◄find_2►
    ◄replace_2►
    ◄find_3►
    ◄replace_3►
    ◄find_4►
    ◄replace_4►
    ◄find_5►
    ◄replace_5►
    ◄find_6►
    ◄replace_6►
    ◄find_7►
    ◄replace_7►
    ◄find_8►
    ◄replace_8►
    ◄find_9►
    ◄replace_9►
    ◄find_10►
    ◄replace_10►
    ◄find_11►
    ◄replace_11►
    ◄find_12►
    ◄replace_12►
    ◄find_13►
    ◄replace_13►
    ◄find_14►
    ◄replace_14►
    ◄find_15►
    ◄replace_15►
    ◄find_16►
    ◄replace_16►
    ◄find_17►
    ◄replace_17►
    ◄find_18►
    ◄replace_18►
    ◄find_19►
    ◄replace_19►
    ◄find_20►
    ◄replace_20►

    Search and replace for your prompt text, twenty pairs deep. EmAySee Text Replace 20 takes one text input plus 20 find_/replace_ pairs, runs every non-empty find against the text in order, and returns the result. If you've ever wanted to clean up an LLM's output ("the" → "the", "a " → "a "), normalize synonyms, swap model-specific tokens, or do prompt templating with placeholder replacement, this is the node - and twenty pairs means you can do a whole normalization pipeline in one box.

    The order matters, and it's the thing most people miss: replacements are applied sequentially, so replace_1 runs on the original text, then replace_2 runs on that result, and so on. That's a feature - it lets you chain transformations (insert a token, then fix the token) - but it also means a pair can undo or re-transform what an earlier pair did. Plan the order like a pipeline, not a set of independent swaps.

    How it works

    Trivial under the hood:

    for i in range(1, 21):
        find_text = kwargs.get(f"find_{i}", "")
        replace_with = kwargs.get(f"replace_{i}", "")
        if find_text:
            text = text.replace(find_text, replace_with)
    

    Empty find strings are skipped, so you can leave unused pairs blank. Python's str.replace is substring-based and global - every occurrence gets replaced, not just the first, and there's no regex. If you need regex (pattern-based) replacement, this isn't the node; that's a different pack's job.

    Inputs and output

    • text (multiline) - the string you're transforming.
    • find_1 … find_20 - the substrings to look for.
    • replace_1 … replace_20 - what each gets replaced with. Leave both blank in a pair to skip it.

    Output is a single STRING - the transformed text. Feed the result into a CLIP Text Encode, a Text Combiner, or another Text Replace node for a second stage.

    Installing it

    One of the ~60 nodes in ComfyUI_EmAySee_CustomNodes. Install via ComfyUI Manager (search "ComfyUI_EmAySee_CustomNodes") or git clone https://github.com/EmAySee/ComfyUI_EmAySee_CustomNodes into custom_nodes/, then restart. No dependencies, no models.

    Where people get burned

    Three classic traps, all from the plain-substring design:

    1. Substring collisions. find = "a" will match the "a" inside every word. For exact token replacement, include the surrounding punctuation or spaces in your find string ("(a)", ", a", etc.).
    2. Order dependence. Because later pairs run on earlier results, a pair that re-introduces text another pair just replaced will make the output look wrong in a way that's hard to spot. Read the pairs top-to-bottom as a script.
    3. No regex, no case-insensitivity. "A" and "a" are different strings here. If your upstream text varies in case, normalize case first or list both variants.

    And the meta-gotcha: twenty pairs of blank inputs is a lot of empty widgets. Most workflows use three or four pairs. The empties are harmless, but they make the node big on the canvas - if you only need two swaps, a plain two-pair replace node (or doing it in the prompt itself) keeps the graph tidier.

    CategoryEmAySee/Text

    Inputs (41)

    NameTypeDefaultDescription
    textSTRING—
    find_1STRING—
    replace_1STRING—
    find_2STRING—
    replace_2STRING—
    find_3STRING—
    replace_3STRING—
    find_4STRING—
    replace_4STRING—
    find_5STRING—
    replace_5STRING—
    find_6STRING—
    replace_6STRING—
    find_7STRING—
    replace_7STRING—
    find_8STRING—
    replace_8STRING—
    find_9STRING—
    replace_9STRING—
    find_10STRING—
    replace_10STRING—
    find_11STRING—
    replace_11STRING—
    find_12STRING—
    replace_12STRING—
    find_13STRING—
    replace_13STRING—
    find_14STRING—
    replace_14STRING—
    find_15STRING—
    replace_15STRING—
    find_16STRING—
    replace_16STRING—
    find_17STRING—
    replace_17STRING—
    find_18STRING—
    replace_18STRING—
    find_19STRING—
    replace_19STRING—
    find_20STRING—
    replace_20STRING—

    Outputs (1)

    NameTypeDescription
    STRINGSTRING—