re.finditer (Regex FindIter)
Get every match as a real match object — the workhorse for structured extraction
- flags
- matches
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.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| pattern | STRING | The regular expression pattern. | |
| string | STRING | The string to search. Used if `string_in` is not connected. | |
| string_inopt | STRING | Input string or list of strings. Overrides `string` widget if connected. | |
| flagsopt | RE_FLAGS | 2 | Regex compilation flags. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| matches | RE_MATCH | — |