Nodes/Comfyui_PDuse/PD text_list_string_add word
ComfyUI Node

PD text_list_string_add word

A batch search-and-replace for your captions, prefixes, suffixes and all

By 7BEII·Created 2 years ago·Updated 15 days ago· 53
PD text_list_string_add word
    • text
    text
    add_prefix
    add_suffix
    replace_from
    replace_to
    insert_word
    insert_position0
    separator

    The text-editor-in-a-node for people who hate editing text 50 times

    PD_TextListStringAddWord ("PD text_list_string_add word") is the batch string editor you reach for when you have a folder full of captions and realize they all need the same fix. Prefix a quality tag to every prompt. Strip a token that appears across a whole batch. Insert a word at a character position. Replace one tag with another across the list. It takes a text input (list-capable, so it can chew through many captions in one run) and applies prefix, suffix, find/replace, and insert operations, in that order, to every item.

    This is caption-hygiene work, and the KB's lora-training.md is blunt that captioning is where training quality lives - but the plumbing of captioning, applying the same edit to a hundred files, is exactly what this node automates. Wire it between the pack's folder text loader and the save-text node and you've replaced an hour of manual editing with one workflow run.

    How it works

    Order of operations matters, and it's baked in: replace first, then insert, then prefix, then suffix. The replace_from/replace_to fields are multiline - one pair per line - so you can do a whole table of replacements in one pass. If replace_to runs out of lines, the missing entries are treated as empty, which means delete. The separator (default a space) is applied intelligently: a prefix that already ends with the separator or a comma doesn't get a doubled one.

    The insert is a character index: insert_position = 0 puts insert_word at the very start, and positions past the end clamp to the end. Everything is applied per item, and if one item errors, it's passed through unchanged rather than killing the batch.

    Inputs and outputs

    • text (required) - the content to edit. List-capable.
    • add_prefix / add_suffix - text to prepend/append.
    • replace_from / replace_to - paired replacements, one per line each.
    • insert_word / insert_position - insert a word at a character index.
    • separator - glue between added words and content, default " ".
    • Output: text - the processed list, same order as input.

    Installing it

    Part of Comfyui_PDuse:

    cd ComfyUI/custom_nodes
    git clone https://github.com/7BEII/Comfyui_PDuse.git
    cd Comfyui_PDuse
    pip install -r requirements.txt
    

    Or via ComfyUI Manager (search "Comfyui_PDuse") and restart.

    The honest gotchas

    The replacement is plain str.replace, so it's not regex and not word-boundary-aware: replacing cat will also hit catalog. If that matters, order your replacement table from longest to shortest. And the delete-on-empty-replace_to behavior is convenient but easy to trigger by accident when you thought you were just leaving a slot blank. Finally, like every node in this pack's text family, the output is a list - downstream consumers need to be list-aware, or you route it through the pack's unpack node. For one-shot batch edits on a caption folder, though, this is genuinely the node you'll reach for.

    CategoryPDuse/Text

    Inputs (8)

    NameTypeDefaultDescription
    textSTRING
    add_prefixoptSTRING
    add_suffixoptSTRING
    replace_fromoptSTRING
    replace_tooptSTRING
    insert_wordoptSTRING
    insert_positionoptINT00–10000插入位置(字符索引,0表示开头)
    separatoroptSTRING

    Outputs (1)

    NameTypeDescription
    textSTRING