ComfyUI Node

Regex Search

Regex Search — find out if a pattern exists, and where

By SeanScripts·Created 2 years ago·Updated 2 years ago· 79
Regex Search
    • BOOLEAN
    • INT
    • INT
    • STRING
    pattern
    string
    flagsM

    Regex Search answers a yes/no question about text: does this pattern appear, and if so, where? It runs a regular expression search over a string and reports the first match's position plus its capture groups. For a beginner the appeal is the boolean output - it's a ready-made condition you can use to gate the rest of a workflow.

    Inputs

    • pattern - the regular expression to search for.
    • string - the text to search.
    • flags - a string of regex flag letters, default "M". This is the pack's convention: a, i, l, m, s, u, x for Python's flags (case-insensitive input, so i and I both work). M is multiline, i is ignore-case, s makes . match newlines.

    Outputs - this is where it gets useful

    Four outputs, and they tell you everything about the first match:

    • BOOLEAN - whether the pattern matched at all.
    • INT - the start position of the match.
    • INT - the end position.
    • STRING - a list of the capture groups (empty if the pattern has no groups).

    The BOOLEAN is the star. Wire it into a switch or condition and the graph can branch on "did the caption mention a cat?" - turning raw text analysis into a workflow decision. The capture groups output lets you pull out the interesting part of a match (e.g. the number in "there are 3 apples") in one step.

    How it works

    It's Python's re.search, which finds the first match only - not all of them (that's this pack's Regex Find All). Positions are character offsets counting from 0. If there's no match, you get False, 0, 0, []. The process_regex_flags helper translates the flag letters into Python's actual flags before the call.

    Install

    Ships with the SeanScripts pack - Manager search ComfyUI-PixtralLlamaVision, or clone the repo. No extra dependencies. Restart after installing.

    Troubleshooting

    • Not matching what you expect - regex is literal by default; special characters like ( . [ need escaping (\( etc.). And the default M flag doesn't mean "match anything" - add i for case-insensitive.
    • Only the first match comes back - by design. Use Regex Find All for every occurrence.
    • Group output looks wrong - groups are numbered by opening parens; a pattern with parens you meant literally will grab text you didn't intend. Escape literal parens.

    If you're new to regex, keep patterns short and test them on a text preview node first. But the boolean output makes this the gentlest on-ramp to regex in the pack.

    CategoryPixtralLlamaVision/Utility

    Inputs (3)

    NameTypeDefaultDescription
    patternSTRING
    stringSTRING
    flagsSTRINGM

    Outputs (4)

    NameTypeDescription
    BOOLEANBOOLEAN
    INTINT
    INTINT
    STRINGSTRING