Nodes/ComfyUI Level Pixel/Text Replace [LP]
ComfyUI Node

Text Replace [LP]

Up to nine find-and-replace pairs in one node

By LevelPixel·Created 2 years ago·Updated 6 months ago· 31
Text Replace [LP]
    • text TEXT
    text
    find1
    replace1
    find2
    replace2
    find3
    replace3
    find4
    replace4
    find5
    replace5
    find6
    replace6
    find7
    replace7
    find8
    replace8
    find9
    replace9

    Chaining nine separate find-and-replace nodes to clean up one string is the kind of thing that makes a graph unreadable fast. Text Replace collapses that into one node with nine numbered find/replace pairs, so a whole pass of substitutions happens in a single box instead of sprawling across the canvas.

    What it does

    Feed it a block of text and up to nine findN/replaceN pairs, and it applies each substitution to the string, handing back the result. This is exact-match, plain-text replacement - no wildcards, no regex, no fuzzy matching (this pack's separate TagReplace-LP node is the fuzzy-threshold version, but it operates on tag strings specifically, not general text). Think templating: swap a placeholder like {{name}} for an actual value, strip out boilerplate phrases that keep showing up in generated captions, or normalize a handful of known-inconsistent spellings in one pass before the text moves on to a CLIP encoder or one of this pack's other text nodes.

    The output type in the schema is a wildcard (*) rather than a plain STRING - a common trick in ComfyUI nodes to let the output socket connect into whatever input type is on the other end without the type-checker complaining, since under the hood it's still text.

    Inputs and outputs that matter

    • text (required, multiline, defaults to empty) - the source text.
    • find1/replace1 through find9/replace9 (all optional, single-line, default empty) - up to nine substitution pairs. Leave a pair empty and it's presumably skipped rather than replacing empty-string-with-empty-string.

    Output: text TEXT - the text after all populated find/replace pairs have been applied.

    Installing it

    Through ComfyUI Manager, search "ComfyUI Level Pixel" or "ComfyUI-LevelPixel." Manual route:

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

    Restart ComfyUI. Text processing only, no models or extra dependencies.

    Common issues & troubleshooting

    A replacement didn't fire. This is exact-match text, so anything less than a character-for-character match on findN won't trigger - different casing, an extra space, or a typo between what's actually in text and what you typed into findN will silently skip that pair rather than error. Copy the exact substring out of your source text if you're not sure it matches.

    Order of operations matters and isn't obvious. With nine pairs available, it's easy to write two rules that interact - one replacement's output text happens to match a later findN and gets replaced again. If your result looks over-processed, check whether an earlier pair's replacement text is accidentally triggering a later pair.

    You need fuzzy or pattern-based matching, not exact text. This node only does literal substring replacement. If you're working with tags specifically and need approximate matching to catch spelling variants, this pack's TagReplace-LP node (with its adjustable match threshold) is the right tool instead - just note it's built for tag strings under the Tags category, not general prose.

    More than nine substitutions needed. Chain a second Text Replace node off the first one's output for additional pairs beyond the nine built in.

    CategoryLevelPixel/Text

    Inputs (19)

    NameTypeDefaultDescription
    textSTRING
    find1optSTRING
    replace1optSTRING
    find2optSTRING
    replace2optSTRING
    find3optSTRING
    replace3optSTRING
    find4optSTRING
    replace4optSTRING
    find5optSTRING
    replace5optSTRING
    find6optSTRING
    replace6optSTRING
    find7optSTRING
    replace7optSTRING
    find8optSTRING
    replace8optSTRING
    find9optSTRING
    replace9optSTRING

    Outputs (1)

    NameTypeDescription
    text TEXT*