Nodes/Basic data handling/search groups (data list)
ComfyUI Node

search groups (data list)

Grab the capture groups from a match, as a data list

By StableLlama·Created about a year ago·Updated 4 days ago· 48
search groups (data list)
    • STRING
    string
    pattern

    You've got a string with one important record hiding in it - "Step 3 of 10: generating" or "epoch 7, loss 0.0412" - and you want the numbers out. This node runs a search with a pattern and hands you the capture groups as a data list, meaning each group becomes its own item ComfyUI processes individually. It's the positional sibling of the pack's RegexGroupDict: that one labels your captures with names, this one just lines them up in order.

    The "data list" output is the point. "Step 3 of 10" with pattern Step (\d+) of (\d+) comes back as two separate STRING items, "3" and "10" - each one available to feed a per-item slot downstream, which is exactly how you get dynamic numbers into a batch without writing a single Python string node.

    How it works

    Under the hood: re.search(pattern, string) once, then list(match.groups()). That last call is worth being precise about, because it's where everyone trips:

    • groups() returns only the parenthesized capture groups, in order, excluding the whole match. Pattern (\d+)-(\d+) on "3-10" gives ["3", "10"], not ["3-10", "3", "10"].
    • It's a search, so only the first match is used. The whole-match string that the search found is not part of the output - if you need it, pattern your own group around it ((.*)).
    • No match means an empty data list. Clean result, no error, and "did it match at all?" is answerable by checking the list has items.

    Inputs and output

    • string - text to search.
    • pattern - the regex; use (...) groups for the parts you want out.

    Output is a data list of STRINGs - one per group, in pattern order. Feed the items into any per-item slot, or into this pack's data-list nodes for slicing, indexing, or converting to SET.

    Installing it

    It's one of the regex family in Basic data handling by StableLlama. Install the pack once:

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

    Restart, or use ComfyUI Manager and search "Basic data handling". Zero dependencies, no model downloads - install is a non-event.

    Gotchas

    • Count your groups carefully. The output order is exactly your pattern's group order; add a group and every downstream index shifts.
    • Nested or optional groups show up too - (a)? that didn't participate comes through as None, which will then do interesting things when you feed it into a node expecting a string. Filter empty items before piping onward.
    • Greedy patterns remain the classic trap. Be explicit about what each group may contain.
    CategoryBasic/STRING/regex

    Inputs (2)

    NameTypeDefaultDescription
    stringSTRING
    patternSTRING

    Outputs (1)

    NameTypeDescription
    STRINGSTRING