Nodes/ComfyUi-MpiNodes/Mpi Text List Replace
ComfyUI Node

Mpi Text List Replace

Find-and-replace across an entire prompt list

By MadPonyInteractive·Created 11 months ago·Updated 5 days ago· 3
Mpi Text List Replace
    • updated_text
    text_list
    find_string
    replace_string

    Every prompt list eventually needs a search-and-replace pass: a style token was renamed, a model's trigger word changed, a banned term has to go before it reaches the sampler. Doing that by hand across a list of dozens or hundreds of prompts is misery. MpiTextListReplace is the find-and-replace for the whole list at once: find_stringreplace_string applied to every item, list in, list out.

    It's the companion to MpiTextListJoin in the pack's TextOps corner. Where Join tacks boilerplate onto the edges of each item, this one surgically rewrites the contents. Both operate on a STRING list and both respect the list contract - INPUT_IS_LIST in, OUTPUT_IS_LIST out - so they slot into the prompt-list pipeline without breaking the data flow. A typical chain: build a list, run a Replace to swap old tokens for new, then sample.

    The inputs that matter

    • text_list - the list of strings (list socket, from a prompt-list producer).
    • find_string - the exact text to look for.
    • replace_string - what to put in its place. Empty is allowed and means "delete the match."

    Output: updated_text, a list of STRINGs with every occurrence of find_string replaced in every item.

    Install

    Part of ComfyUi-MpiNodes. ComfyUI Manager (search "MpiNodes" / publisher "mad-pony-interactive"), or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/MadPonyInteractive/ComfyUi-MpiNodes
    

    Restart. No extra deps - it's Python's str.replace per item, which also tells you its limits.

    Where people get burned

    Three things. First, it's a plain substring replace, not regex and not case-insensitive - "cinematic" won't catch "Cinematic" or "cinema". Second, the classic footgun: an empty find_string. Python's str.replace with an empty finder inserts the replacement between every character - "cat".replace("", "-") gives "-c-a-t-". It won't error; it'll just mangle every item into a string of separator characters. Leave find_string non-empty. Third, the list-socket rule again: feed it a single string and you get a one-item list back, silently. This node edits lists; if you're editing one block of text, you want MpiBatchTextReplace (files) or a plain single-string replace - not this.

    CategoryMpiNodes/TextOps

    Inputs (3)

    NameTypeDefaultDescription
    text_listSTRING
    find_stringSTRING
    replace_stringSTRING

    Outputs (1)

    NameTypeDescription
    updated_textSTRING