Nodes/comfy-ovum/re.Match[index] (Regex Match Select)
ComfyUI Node

re.Match[index] (Regex Match Select)

Pick one match out of a finditer list by index

By sfinktah·Created about a year ago·Updated 10 months ago· 7
re.Match[index] (Regex Match Select)
  • matches
  • match
index0

re.finditer hands you all the matches; sometimes you only want the third one. OvumReMatchSelect is the tiny utility that indexes into that list - matches[2] - and hands back a single RE_MATCH object you can then pass to re.Match.group or re.Match.span. It's the "pick one from the pile" node, and it's what makes finditer usable for targeted extraction instead of always having to handle the whole batch.

How it works

Inputs are matches (the list of RE_MATCH objects, typically from finditer) and index (an INT, min 0, default 0). It clamps the index to the valid range - ask for match #10 in a 3-match list and you get the last one, not an error. Edge cases are handled without crashing: an empty list returns a None match with a "Empty list" status, and a non-list input passes through with a status note.

Output: match - a single RE_MATCH object (this one is not list-shaped, so it plugs directly into a single-match consumer). The status readout shows which match was selected, e.g. "Selected #3/5", and flags if the selected slot was None.

The workflow pattern

finditer → select → group is the pipeline for "I want the Nth occurrence." Parse a config string with repeated key=value blocks, finditer all of them, select match #2, and pull its value with re.MatchGroup - no manual list-slicing, no off-by-one scrambles (the clamping saves you). You can even drive index from a loop node to walk through every match one at a time, which turns finditer+select into a manual iterator.

Installing it

Ships in comfy-ovum. ComfyUI Manager → search "comfy-ovum", or:

cd ComfyUI/custom_nodes
git clone https://github.com/sfinktah/comfy-ovum

Restart, find it under ovum/regex. No models; light pure-Python deps installed by Manager.

The gotcha

Remember the index is zero-based: the first match is index 0. The clamp means an out-of-range index silently gives you the last match rather than failing - which is friendly most of the time and hides bugs the rest of it. If a selected slot is None (a no-match entry from an earlier step), you'll get None through to group, which returns None too. If "the match I wanted" keeps being the wrong one, check the status readout - it tells you exactly which slot it picked.

Categoryovum/regex

Inputs (2)

NameTypeDefaultDescription
matchesRE_MATCHThe list of match objects.
indexINT0The index of the match to select from the list.

Outputs (1)

NameTypeDescription
matchRE_MATCH