Nodes/comfy-ovum/re.Match.group (Regex Match Group Selector)
ComfyUI Node

re.Match.group (Regex Match Group Selector)

The extraction node — pull captured groups out of any match object

By sfinktah·Created about a year ago·Updated 10 months ago· 7
re.Match.group (Regex Match Group Selector)
  • match
  • group
  • groups
  • groupdict
n0
default

This is the node you'll actually live in. Every matcher in the pack hands back RE_MATCH objects, and OvumReMatchGroup is what turns those objects into the strings, tuples, and dicts you can wire into the rest of your workflow. It mirrors Python's match.group(), match.groups(), and match.groupdict() on one node, with three outputs so you grab exactly the shape you need. If you built a pattern with parentheses to capture data, this is where that data comes out.

How it works

Feed it a match (single object or list), optionally set n, and it computes:

  • group - match.group(n). Group 0 is the entire match; 1, 2, 3… are your capturing groups. This is the output you'll use most.
  • groups - match.groups(), the tuple of all capturing groups at once. Wire this to a list consumer when you want everything.
  • groupdict - match.groupdict(), a DICT of all named groups ((?P<name>...)) keyed by name. Best for patterns with several labeled captures.

Optional inputs: n (the group number; default 0 = whole match) and default (the value substituted when a group didn't participate in the match - handy so absent groups don't hand you None and break downstream string nodes).

All three outputs are list-shaped: pass in a list of matches and you get aligned lists back, with None/empty for no-match slots instead of a crash.

The workflow pattern

Match → group is the bread and butter of parsing. re.search a filename against ^(.+?)_(\d{5})\.png$, then re.MatchGroup with n=1 for the base name and n=2 for the sequence number - two copies of the node or one pass through groups for the tuple. Named groups pay off here: (?P<base>.+?)_(?P<seq>\d{5}) and groupdict gives you {"base": "...", "seq": "00042"} in one output, which is beautifully self-documenting downstream.

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 n=0 is the entire match, and your first actual capture is n=1 - a beginner wiring n=0 expecting "group one" gets the whole match and wonders why nothing was extracted. Also, an n beyond the pattern's group count returns None (the node guards the IndexError), so validate your pattern against re.MatchView if you're unsure how many groups exist. And if you want the raw matched text without any group gymnastics, group 0 is exactly that.

Categoryovum/regex

Inputs (3)

NameTypeDefaultDescription
matchRE_MATCHThe match object (or list of match objects).
noptINT0The group number to retrieve. Group 0 is the entire match.
defaultoptSTRINGThe default value to return for `groups()` and `groupdict()` if a group did not participate in the match.

Outputs (3)

NameTypeDescription
groupSTRING
groupsSTRING
groupdictDICT