Nodes/honda-nodes/πŸ”€ Text Match
ComfyUI Node

πŸ”€ Text Match

A yes/no on a string, with or without regex

By AvarayΒ·Created 14 days agoΒ·Updated 12 days agoΒ· 0
πŸ”€ Text Match
    • Match
    • Matched Text
    β—„text_inputβ€”β–Ί
    β—„patternβ–Ί
    β—„use_regexfalseβ–Ί
    β—„ignore_casefalseβ–Ί
    β—„full_matchfalseβ–Ί

    There's a specific frustration in building ComfyUI automations: you have a string, you need a boolean, and there's no obvious place to get one. Text Match is that place. Ask it whether a prompt contains "nsfw", whether a filename ends in .png, whether a classifier's output says anime - get a BOOLEAN you can route on.

    How it works

    Two engines behind one switch.

    With Use Regex off, it's literal substring search: lowercase both sides if Ignore Case is on, then check containment. With Full Match also on, it becomes equality instead. The Matched Text output is a neat touch here - for a case-insensitive substring hit it returns the slice of the original string at the position it found, so you get the actual text back with its original capitalisation rather than the lowercased haystack.

    With Use Regex on, it hands the pattern to Python's re - re.search normally, re.fullmatch when Full Match is on. That means real regex: character classes, anchors, alternation, groups. \d+ for a run of digits, ^(sd|sdxl)_ for a filename prefix, \b(blurry|lowres)\b to catch quality tags as words.

    Two behaviours that are quietly important. An empty pattern never matches - no pattern means False, not "everything". And an invalid regex does not throw: it catches re.error, prints one line to the console, and returns False with empty matched text. Your workflow keeps running with a permanently false branch and no red node to tell you why. If a regex branch "just never fires", print your pattern and test it in a scratch run before you rebuild the graph around it.

    The inputs and outputs that matter

    Text Input is a forced input - it must come from another node. That's deliberate: this node is for inspecting strings the graph produced, not for typing a literal. Drop a Text node next to it if you need a constant to test against.

    Pattern is the string or regex, default empty (which, per above, matches nothing). Use Regex, Ignore Case, Full Match - all default off, and for regex work you'll want Ignore Case on more often than not, since prompts don't agree on capitalisation.

    Outputs: Match (BOOLEAN) and Matched Text (STRING, empty when there's no match). The second one is more useful than it looks - for a regex with a capture-worthy shape it gives you what matched, which you can then feed to a rename or a metadata field. It's group(0) though, not the first capture group: the pack has a JSON Get Value for structured extraction, and this isn't it.

    What to do with a boolean in ComfyUI is the honest limitation. There's no core "if" that rewires a graph, so in practice you use it three ways: as an input to the pack's own logic/switch nodes if you have them, as a print-to-console probe while debugging a classifier, or as a guard where you've got a node that accepts a boolean toggle. The most valuable non-obvious use is validation - "does this metadata string contain PngText before I hand it to the writer", "is this caption empty" - because it lets you spot a broken branch in one run instead of in one bad batch.

    How to install it

    Part of Avaray/honda-nodes - ComfyUI Manager β†’ Node Pack β†’ search Honda Nodes β†’ Install β†’ restart. Manual:

    cd ComfyUI/custom_nodes
    git clone --depth 1 https://github.com/Avaray/honda-nodes.git
    cd honda-nodes
    python install.py
    

    This node is pure stdlib and doesn't need the installer - but the same script downloads jq and ime for the rest of the pack, so run it once. Requires ComfyUI 0.38.0+ (V3 schema API). No pip packages, no models.

    Common issues

    Always false, no error. In order: empty pattern; Full Match on when you wanted substring; a pattern mismatch hidden by case (turn on Ignore Case); or a regex that doesn't compile, which fails silently to the console. Print the pattern once.

    Regex behaves differently than you expect. Python's re, not JavaScript's or PCRE. Backslashes in the widget need to survive as a single backslash - type \d+, not \\d+. Greedy quantifiers grab more than you want; .*? is your friend.

    The matched text is the whole match, not my capture group. Correct - it's group(0). Split the string apart with Text Replace or a JSON node if you need a specific group.

    It matches "art" inside "cartoon". Substring semantics without word boundaries. \bart\b with regex on.

    I can't type into Text Input. Forced input by design; use a Text node upstream.

    Category⚑️ Honda Nodes/πŸ”€ Text

    Inputs (5)

    NameTypeDefaultDescription
    text_inputSTRINGThe text to search within (must be connected from another node).
    patternSTRINGThe string or regex pattern to search for.
    use_regexBOOLEANfalseIf enabled, treats the 'Pattern' field as a Python Regular Expression. Uses Python's re module (re.search). Example: r'\d+' matches one or more digits.
    ignore_caseBOOLEANfalseIf enabled, the search will be case-insensitive.
    full_matchBOOLEANfalseIf enabled, the pattern must match the entire text (re.fullmatch / exact equality). If disabled, the pattern only needs to appear anywhere in the text (re.search / substring).

    Outputs (2)

    NameTypeDescription
    MatchBOOLEANβ€”
    Matched TextSTRINGβ€”