ComfyUI Node

text_modifier

Clean up and batch-replace text without chaining five nodes

By cardenluo·Created 2 years ago·Updated 18 days ago· 309
text_modifier
    • processed_text
    text
    repair_typeNone
    replace_targets{text1}|{text2}
    replace_content{A}|{B}
    remove_targets{text1}|{text2}

    If you've ever piped an LLM captioner's output straight into a prompt and had to strip stray newlines, fix inconsistent casing, or swap out a handful of words before it was usable, text_modifier is built for exactly that cleanup step - one node that does find-and-replace, removal, and a menu of common text-formatting fixes, instead of chaining several separate string nodes together.

    Multi-target replace and remove, done in parallel. The standout feature here is that replace_targets/replace_content and remove_targets all accept pipe-delimited lists, and per the node's own description, that means you can swap or strip several different terms in a single pass rather than needing a separate replace node per word. The node documents its own syntax directly: targets = "{man}|{dog}" paired with replacements = "{girl}|{cat}" replaces both simultaneously - man becomes girl, dog becomes cat, in one operation - and the same |-separated pattern works for remove_targets when you just want terms gone rather than swapped. Both fields support regular expressions too, so this isn't limited to literal word matches if you need pattern-based cleanup.

    The repair_type dropdown covers common formatting fixes as one-click presets rather than requiring a regex for each: extract digits only, extract letters only, uppercase, lowercase, extract Chinese characters only, strip punctuation, strip line breaks, strip blank lines, strip spaces, strip general formatting, and a character-count utility, plus three more beyond what's listed in the schema's sample. Set this alongside your replace/remove fields and both operations apply - repair-type cleanup plus your custom replacements - rather than one replacing the other.

    Output. A single STRING, processed_text - your input run through whichever combination of removal, replacement, and repair-type cleanup you configured.

    Where this actually earns its slot in a workflow. Two obvious spots: right after a vision-language captioner or LLM node, cleaning up whatever raw text it handed back before it reaches your sampler (stripping the model's tendency to add line breaks or stray punctuation, say); or right before a prompt-scheduling node like this pack's own text_Splitter, normalizing formatting so the split behaves predictably. It's also a reasonable place to do simple content substitution across a template-driven prompt - swap a placeholder character name for a real one across an entire block of generated prompt text in one step, instead of hand-editing.

    Installing it. Standard for the whole pack - search "ComfyUI-Apt_Preset" in ComfyUI Manager, or clone directly:

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

    Run install.bat on Windows for dependencies, then restart. Pure text processing, no models or GPU work involved - it should function as soon as the pack loads cleanly.

    Troubleshooting. If a replacement isn't landing, the most common mistake is mismatched list lengths - replace_targets and replace_content are paired positionally by their |-separated entries, so three targets need three replacements in the same order, not two. If you're leaning on the regex support in remove_targets/replace_targets, remember an unescaped regex special character (., (, ), and so on) in what you meant as literal text will be interpreted as a pattern, not a literal match - escape it if that's not what you want. And if the node's missing from your install entirely, that's most likely the pack-wide IMPORT FAILED issue documented on r/comfyui for a missing downstream dependency - check the ComfyUI console log at startup and reinstall via Manager's "install missing custom nodes" rather than assuming this node specifically is broken.

    CategoryApt_Preset/prompt

    Inputs (5)

    NameTypeDefaultDescription
    textSTRING
    repair_typeCOMBONone15 options: None, 取数字, 取字母, 转大写, 转小写, 取中文, +9
    replace_targetsSTRING{text1}|{text2}
    replace_contentSTRING{A}|{B}
    remove_targetsSTRING{text1}|{text2}

    Outputs (1)

    NameTypeDescription
    processed_textSTRING