Nodes/comfy-ovum/re.finditer (Regex FindIter)
ComfyUI Node

re.finditer (Regex FindIter)

Get every match as a real match object — the workhorse for structured extraction

By sfinktah·Created about a year ago·Updated 10 months ago· 7
re.finditer (Regex FindIter)
  • flags
  • matches
pattern
string
string_in

re.finditer is what you want when "every match" isn't enough - you want every match plus its groups, positions, and context. OvumReFindIter scans a string left to right and returns each hit as a full RE_MATCH object, which is exactly what the rest of the pack's inspector nodes are designed to chew on. findall gives you bare strings; finditer gives you the whole apparatus. When you need to loop over a list of filenames, extract structured data from a prompt, or slice text by position, this is the node.

How it works

Give it pattern and string, and it runs pat.finditer() over each input, collecting the matches into a list - a list of RE_MATCH objects, one per input string, through the matches output. Each RE_MATCH object is then fed onward: re.MatchSelect to pick one specific hit by index, re.MatchGroup to pull group contents, re.MatchSpan for start/end positions, re.MatchView to eyeball the whole thing.

Inputs:

  • pattern - multiline regex field.
  • string - the text to scan.
  • string_in - optional, overrides the widget, accepts a list of strings (each gets its own match list).
  • flags - RE_FLAGS from the re.compile flags node (default IGNORECASE on).

Like every node in this family, a no-match just yields an empty list rather than an error, and the status readout tells you how many matches were found.

The workflow pattern that matters

finditer is the front end of a two-stage pipeline. Stage one: find everything. Stage two: pick a match with re.MatchSelect (index into the list) or run them all through re.MatchGroup to extract group values, then feed those into a loop node. Classic example: parse every width=NNN out of a config string, select match #2, and pull its group - or take a list of tag fragments out of a prompt and forward them as a proper list to downstream logic.

Installing it

Ships in comfy-ovum; install via 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 deps - Manager handles the pack's requirements automatically.

The gotcha

Because the output is match objects, not strings, a beginner wires matches straight into a text node and gets a repr instead of content. That's not a bug - you need to pass it through re.Match.group (or re.MatchView) to see the text. If all you want is the matched strings with zero fuss, re.findall does that in one hop. Choose finditer when you need structure: groups, positions, or per-match selection downstream.

Categoryovum/regex

Inputs (4)

NameTypeDefaultDescription
patternSTRINGThe regular expression pattern.
stringSTRINGThe string to search. Used if `string_in` is not connected.
string_inoptSTRINGInput string or list of strings. Overrides `string` widget if connected.
flagsoptRE_FLAGS2Regex compilation flags.

Outputs (1)

NameTypeDescription
matchesRE_MATCH