Nodes/comfy-ovum/re.Match.span/start/end (Regex Match Span)
ComfyUI Node

re.Match.span/start/end (Regex Match Span)

Get the exact character positions of a match

By sfinktah·Created about a year ago·Updated 10 months ago· 7
re.Match.span/start/end (Regex Match Span)
  • match
  • span
  • start
  • end
n0

Sometimes you don't need the matched text - you need where it is. OvumReMatchSpan returns the character positions of a match: span() gives you the (start, end) tuple, and start() / end() give the two ends separately. If you're slicing the original string yourself, measuring how far into a line something appears, or validating that a match landed in the expected region, this is the node. It's the positional cousin of re.Match.group, and in ComfyUI terms it's how you turn regex results into numbers other nodes can use.

How it works

Feed it a match object (or a list), optionally set n for a specific capturing group, and it computes Python's match.span(n), match.start(n), and match.end(n):

  • span - the (start, end) 2-tuple for the match. (The schema types this as INT, but the code passes through Python's span tuple, so expect a (a, b) pair - group 0's span, or group n's.)
  • start - the start index, an integer.
  • end - the end index, an integer (exclusive, Python-style).

All three are list-shaped, so a list of matches yields aligned lists, with None entries for no-match slots. The optional n input (default 0) selects a group; a group number that doesn't exist returns None rather than raising.

Why you'd reach for it

Three real jobs. One: slicing - if you have the original string elsewhere, start/end are the exact indices for a slice node to carve out the matched region without re-matching. Two: positional logic - "does the match start before character 20?" is a genuine question when parsing fixed-width fields or validating that a match occurred in the header rather than the body. Three: measuring - the length of a match is just end - start, which is a quick way to compute the size of a matched token.

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

Two things bite here. First, end is exclusive: a match of "cat" in "the cat sat" spans (4, 7), and slicing [4:7] gives you "cat" - get the off-by-one wrong and you'll be off by one forever. Second, the span output is a tuple wearing an INT label in the schema; if you feed it straight into a node that expects a bare integer, that type mismatch will confuse you until you realize you should be using start or end instead. For most math, use the separate start/end outputs.

Categoryovum/regex

Inputs (2)

NameTypeDefaultDescription
matchRE_MATCHThe match object (or list of match objects).
noptINT0The group number for which to get the span. Group 0 is the entire match.

Outputs (3)

NameTypeDescription
spanINT
startINT
endINT