Nodes/ComfyUI-Basic-Math/String Comparison | Basic
ComfyUI Node

String Comparison | Basic

Comparing text, checking substrings, and regex from the node graph

By akatz-ai·Created about a year ago·Updated 11 months ago· 16
String Comparison | Basic
    • BOOLEAN
    a
    b
    operation
    case_sensitivetrue

    Most of this pack compares numbers, but workflows also make decisions about text - model names, filenames, prompts, tags. StringComparison ("String Comparison | Basic") is the odd one out that handles that: it takes two strings, a and b, runs one of six operations, and returns a BOOLEAN.

    The operations go beyond plain equality:

    • a == b / a != b - exact match or not
    • a IN b - is a a substring of b?
    • a MATCH REGEX(b) - does a match the regular expression in b?
    • a BEGINSWITH b / a ENDSWITH b - prefix and suffix checks

    There's also a case_sensitive toggle (default true). Flip it off and both strings are lowercased before any comparison, so "SDXL" and "sdxl" become equal.

    The inputs that matter

    • a, b - the two strings.
    • operation - what kind of comparison.
    • case_sensitive - the one you'll forget until a filename matches the wrong way. When true (the default), "Model" and "model" don't match.

    Why you'd reach for it

    This is routing logic for text. A common pattern: a node outputs a model name or a tag, and you want the graph to branch based on what it says. Check whether a checkpoint name starts with "flux", whether a tag list contains "anime", whether a filename ends with a certain extension - all single-node operations. The regex option is the power move: a MATCH REGEX(b) lets you match patterns like step_\d+ instead of exact strings, which is how you detect "any numbered step suffix" rather than one specific value.

    One implementation detail matters if you're a regex user: the matching is anchored to the start. The node uses re.match, which only looks for a match at the beginning of a - so a regex like anime will not match "very anime style". If you want a match anywhere, prefix your pattern with .*, like .*anime. That trips people up every single time, and it's not documented anywhere in the pack.

    Installing it

    Standard pack install - pure Python (it uses the stdlib re module, no extra deps):

    cd ComfyUI/custom_nodes
    git clone https://github.com/akatz-ai/ComfyUI-Basic-Math
    

    Restart ComfyUI, find it under Basic Math ➕ → Boolean as "String Comparison | Basic". Or use ComfyUI Manager → **Install Custom Nodes → search "ComfyUI-Basic-Math"`.

    The gotchas

    Three things. The re.match anchoring above is the big one. Second, an invalid regex doesn't crash the graph - it just returns false, which is graceful but means a typo silently behaves as "no match." Third, remember this is a strict-boolean output, so it feeds switches and BooleanLogic directly. And expect the | Basic menu suffix like everything else in the pack.

    CategoryBasic Math ➕/Boolean

    Inputs (4)

    NameTypeDefaultDescription
    aSTRING
    bSTRING
    operationCOMBO6 options: a == b, a != b, a IN b, a MATCH REGEX(b), a BEGINSWITH b, a ENDSWITH b
    case_sensitiveBOOLEANtrue

    Outputs (1)

    NameTypeDescription
    BOOLEANBOOLEAN