Nodes/ComfyUI-mnemic-nodes/πŸ”„ Find / Replace Text
ComfyUI Node

πŸ”„ Find / Replace Text

The node you don't need until your prompt is a mess

By MNeMoNiCuZΒ·Created 3 years agoΒ·Updated 6 days agoΒ· 108
πŸ”„ Find / Replace Text
    • string
    β—„stringβ–Ί
    β—„findβ–Ί
    β—„replaceβ–Ί

    A find-and-replace node looks like a joke entry in a node pack, and in a way it is. You can't generate anything with it. It doesn't touch pixels. But the moment you start wiring prompts together - a wildcard processor here, a tag loader there, an LLM writing your prompt for you - you end up with a string that's almost right and one stuck , away from being usable. That's the gap this fills.

    This is MNeMiC_FindReplaceText from ComfyUI-mnemic-nodes, the grab-bag pack by MNeMoNiCuZ (mnemic2 on Reddit, the same person behind the aesthetic-scorer tool). It's a one-person pack, not a framework, and the small nodes are the ones that actually earn their install.

    What it actually does

    Three inputs, one output, and the entire logic is one line of Python. From the shipped source (nodes/find_replace_text.py):

    return io.NodeOutput(string.replace(find, replace) if find else string)
    

    So: plain str.replace. Not regex, not a pattern engine, not case-insensitive. It scans for the literal text you typed in find and swaps in replace, every occurrence, front to back. If find is empty the node hands your string straight back untouched - no error, no runaway loop, which is a nicer failure mode than you'd expect from a node this small.

    The three widgets are all single-line STRING fields, all optional to wire up:

    • string - the text to process. Usually wired in from a wildcard processor, an LLM node, or a text encode's prompt.
    • find - literal text, case-sensitive. Empty passes the string through.
    • replace - what goes in its place. Empty deletes the matches, which is the whole "strip this junk out" use case.

    One output, string, typed STRING - the cleaned text, ready for a CLIP Text Encode, a save-text node, a filename, or another find/replace downstream.

    Where it earns its keep

    Four things people actually do with it:

    • Make a log readable. Replacing , with a newline turns a wall of comma-separated tags into a list you can skim. That's literally how people debug wildcard workflows - when you're checking what the wildcard picked this run, a line-per-tag dump beats one long sentence.
    • Strip syntax the model doesn't want. Prompt pasted from an A1111-era gallery with (masterpiece:1.2) weights? Yank the weights out before they hit an encoder that doesn't read them.
    • Sanitise filenames. Prompt text used as an output filename breaks on \ / : * ? " - swap those for - and the save node stops throwing.
    • Fix tags between two encoders. Same prompt, one model wants 1girl, another wants 1 girl. Two nodes, two branches.

    If your problem is case (Red vs red), or trimming whitespace, or punctuation, this node is the wrong tool - the same pack's String Cleaning node has ordered operations for exactly those, and doing them here is just pain.

    Install

    The pack installs like any other:

    cd ComfyUI/custom_nodes
    git clone https://github.com/MNeMoNiCuZ/ComfyUI-mnemic-nodes
    # restart ComfyUI
    

    Or search ComfyUI-mnemic-nodes (publisher mnemic) in ComfyUI Manager, which will pull requirements.txt for you. Worth knowing what's in there first: groq, transformers, tiktoken, imageio, opencv-python, piexif, colorama, wonderwords, python-dotenv. You can't install just this node - it's the whole pack - and those dependencies belong to its LLM, audio-visualizer and metadata nodes, not the text one.

    The .env setup the README talks about is only for the ✨ LLM nodes. This one needs no keys, no API, no config.

    Gotchas

    It replaces all of them. There's no "first occurrence only" and no index. Find a, and you've gutted every a in your prompt. Find something shorter than you intended and you will find out why the output looks like it lost letters.

    Case matters, exactly. find=red won't touch Red, RED, or red.. If you need both, chain two nodes, or normalise case upstream.

    Empty find is a silent no-op. Nice, but it means a workflow driven by an external value (say, a variable that came back blank from a wildcard) quietly does nothing instead of yelling. If your replacement "isn't happening," check that find actually arrived.

    Single-line widgets. All three fields are one-liners, so pasting a long prompt into the widget is clumsy. Right-click β†’ Convert widget to input and feed it from a string primitive or the upstream node - the standard plumbing move for any value node, and how you make the replacement data-driven instead of hand-typed.

    Old ComfyUI won't load the pack at all. These nodes are written against the newer backend authoring API (from comfy_api.latest import io, io.ComfyNode, io.Schema) rather than the classic NODE_CLASS_MAPPINGS style. That's not broken - core's own primitive nodes ship this way - but a ComfyUI old enough to predate the API will fail the import for the whole pack. Update, then debug.

    Search for it by its display name - πŸ”„ Find / Replace Text in the ⚑ MNeMiC Nodes category. Several packs ship a similarly named text node, and grabbing the wrong one mid-workflow is a detour you don't get back.

    Category⚑ MNeMiC Nodes

    Inputs (3)

    NameTypeDefaultDescription
    stringSTRINGThe text to process.
    findSTRINGLiteral text to find. Matching is case-sensitive; empty leaves the string unchanged.
    replaceSTRINGReplacement text for every match. Empty deletes the matched text.

    Outputs (1)

    NameTypeDescription
    stringSTRINGThe text with every matching occurrence replaced.