Nodes/comfyui_tag_filter/TagWildcardFilter
ComfyUI Node

TagWildcardFilter

Every *hair, none of the hair_*

By sugarkwork·Created 2 years ago·Updated 6 months ago· 87
TagWildcardFilter
    • tags
    • found
    tags
    wildcard

    TagWildcardFilter is the pattern matcher of the pack. Where TagFilter and TagSelector work on categories - "keep the expression tags" - this one works on name shapes: "keep every tag ending in _hair" or "keep everything that starts with hair_". It's the node you reach for when the category file's opinion doesn't match your own, because it doesn't consult the category file at all. Pure string matching.

    The input is simple: tags in, and a single wildcard pattern. The wildcard uses the classic * glob:

    • *hair matches long_hair, short_hair, green_hair - anything ending in _hair.
    • hair* matches hair_ornament, hair_accessory, hair_bun - anything starting with hair_.
    • *hair* matches anything containing hair anywhere.

    And here's the subtle default: if you type a pattern with no asterisk at all, it's treated as *hair* - a substring match. So wildcard: hair behaves like *hair*. That catches people who expected an exact match and got a substring instead, but it's actually a convenience once you know it.

    The mechanics

    Under the hood it's not even a glob engine - the pattern is normalized (lowercase, spaces to underscores, matching the pack's tag format) and turned into a ^...$ anchored regex with * expanded to .*. No wildcard means a plain in substring check. Either way, matching happens against the normalized tag, so long hair in your string and long_hair in the pattern line up correctly.

    Outputs are tags (the filtered string) and found (a BOOLEAN telling you whether anything survived). found is the useful one for gating - "does this tag set contain any *hair at all?" is a real conditional you'll want for routing later in the graph, and you get it for free.

    Where it shines and where it doesn't

    This is the perfect companion to TagFilter. Run TagFilter to strip to the categories you care about, then TagWildcardFilter to carve out a specific naming family the category system lumps together - say, keeping only twintails and long_hair from a hair_style bucket by matching *twintails,*hair. The two nodes attack the same problem from different angles and compose well.

    It won't help with typos or near-misses - *hear matches nothing and found goes false. There's no fuzzy matching here; that's what TagSelector's flexible_filter is for. And the whole thing is case-insensitive and underscore-normalized, which is almost always what you want, just don't expect regex alternation or character classes - * is the only special character.

    Install

    Boring answer, same as every node in this pack: ComfyUI Manager search "comfyui_tag_filter", or

    cd ComfyUI/custom_nodes
    git clone https://github.com/sugarkwork/comfyui_tag_fillter
    

    Restart, done. No dependencies, no model downloads - it's pure string handling in ~20 lines of Python, which is exactly the right size for what it does.

    Categorytext

    Inputs (2)

    NameTypeDefaultDescription
    tagsSTRING
    wildcardSTRING

    Outputs (2)

    NameTypeDescription
    tagsSTRING
    foundBOOLEAN