ComfyUI Node

test

Does this string match? The boolean your branches have been missing

By StableLlama·Created about a year ago·Updated 4 days ago· 48
test
    • BOOLEAN
    string
    pattern

    Every workflow eventually needs to make a decision about text, and ComfyUI's stock toolbox is bad at it. "Does this filename contain a version number?" "Is this a negative prompt?" "Is this caption a known style tag?" Those are pattern questions, and this node answers them with a clean BOOLEAN: run a search, return True if anything matched, False if not. That output feeds straight into this pack's if/else, flow-select, and other control-flow nodes, which is the entire point.

    The name undersells it. This isn't a debugging utility - it's the switch that turns a wall of text into a branch. Filenames, prompts, whatever string you're processing, test turns "does it look like X" into something the graph can route on. In an automation-heavy ComfyUI setup it's one of the first regex nodes you'll actually wire into a real workflow.

    How it works

    re.search(pattern, string) and a truthiness check: True if a match was found anywhere in the string, False otherwise. Three semantics worth being precise about:

    • It's a search, not a full-match. pattern = "\d+" returns True for "image_42" because a digit appears somewhere. If you need the whole string to match, anchor it: ^\d+$.
    • Only the first match matters - it stops after one, so this is fast even on long text.
    • An empty pattern matches anything (including empty strings), which is mathematically correct re behavior and practically a way to make the node always return True.

    Inputs and output

    • string - the text to check.
    • pattern - the regex.

    Output is a single BOOLEAN. Wire it into the pack's control-flow nodes, a STRING-comparison gate, or anywhere a boolean is accepted.

    Installing it

    Part of Basic data handling by StableLlama:

    cd ComfyUI/custom_nodes
    git clone https://github.com/StableLlama/ComfyUI-basic_data_handling
    

    Restart, or install via ComfyUI Manager (search "Basic data handling"). No dependencies, no models - the pack is pure stdlib, so it won't fight your other nodes.

    Gotchas

    • Search-not-match is the classic surprise: an unanchored pattern returns True for containing a match. Anchor with ^/$ when you want an exact check.
    • A malformed pattern raises a hard error; a valid-but-wrong one silently returns False. When a branch never fires, check the pattern for "matches nothing" before suspecting the node.
    • Case sensitivity is on by default - "PNG" won't match png. Preprocess the string to lowercase, or write the case variants into the pattern, if that's what your data needs.
    CategoryBasic/STRING/regex

    Inputs (2)

    NameTypeDefaultDescription
    stringSTRING
    patternSTRING

    Outputs (1)

    NameTypeDescription
    BOOLEANBOOLEAN