Nodes/ComfyUI_EmAySee_CustomNodes/EmAySee Remove Words From Text
ComfyUI Node

EmAySee Remove Words From Text

Surgically remove words from a prompt — whole words, not substrings

By EmAySee·Created about a year ago·Updated 4 months ago· 2
EmAySee Remove Words From Text
    • cleaned_text
    main_textA dog, a cat, and a bird.
    words_to_removedog, cat, and

    Strip specific words out of a longer text. Give it a main string and a comma-separated list of words to delete, and it returns the text with those words gone - matching whole words only, case-insensitively, and collapsing the leftover double spaces so you don't end up with holes. It's the "clean this up before it hits the CLIP encoder" node.

    How it works

    Two inputs:

    • main_text (multiline) - what you're cleaning. Defaults to A dog, a cat, and a bird.
    • words_to_remove (multiline) - comma-separated words to delete, defaulting to dog, cat, and.

    Output cleaned_text. The mechanism is a regex built from your words (escaped, so punctuation in words doesn't break it), wrapped in word boundaries \b(...)\b so it only matches whole words - cat won't touch caterpillar. It matches case-insensitively (Dog gets removed too), and after removal it squeezes runs of multiple spaces down to one and trims the ends. So the default input gives you A , a , a bird. - wait, no. With "and" removed and spaces collapsed, you get A , a , a bird. Hmm, the comma stays because it removes the word, not the punctuation. Real output from the default would be something like A , a , a bird. - the commas survive and look awkward.

    That's the honest gotcha: this node removes words, not punctuation or the surrounding grammar. "Remove dog, cat, and from A dog, a cat, and a bird." leaves you with A , a , a bird. The sentences are no longer grammatical - there's no smart re-joining. For tag lists (the common use case) that's fine: red hair, smiling, red hair minus red hair gives , smiling, and you may want to run the result through a dedup/cleaner afterwards. For flowing prose, expect punctuation leftovers.

    Where it fits

    • Stripping unwanted tags out of an auto-generated caption before encoding.
    • Removing "quality boosters" (masterpiece, best quality) from a copy of a prompt to A/B test their effect.
    • Banning a trigger word from a batch of prompts.

    Installing it

    Part of ComfyUI_EmAySee_CustomNodes. ComfyUI Manager → search the pack title → Install, or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/EmAySee/ComfyUI_EmAySee_CustomNodes
    # restart ComfyUI
    

    Under EmAySee_Text, no dependencies - it's re.sub with a bit of cleanup.

    Bottom line

    A precise word-removal tool that won't mangle substrings but also won't fix your grammar. Feed it tag lists and you're golden; feed it prose and accept the orphaned commas.

    CategoryEmAySee_Text

    Inputs (2)

    NameTypeDefaultDescription
    main_textSTRINGA dog, a cat, and a bird.
    words_to_removeSTRINGdog, cat, and

    Outputs (1)

    NameTypeDescription
    cleaned_textSTRING