Nodes/comfy-ovum/re.split (Regex Split)
ComfyUI Node

re.split (Regex Split)

Slice strings on any regex — smarter than a simple delimiter split

By sfinktah·Created about a year ago·Updated 10 months ago· 7
re.split (Regex Split)
  • flags
  • parts
pattern
string
string_in
maxsplit0

Splitting a string on a comma is easy; splitting it on "one or more commas, spaces, or newlines" is what re.split is for. OvumReSplit brings Python's regex split to ComfyUI, and it's the node to reach for when a plain delimiter node leaves you with empty strings and whitespace gunk. Clean up a messy CSV, break a prompt into its comma-separated tags, split a path list on newlines, or chop a config block into key/value pairs - the delimiter is a regex, so it matches messy reality instead of assuming tidy input.

How it works

You give it pattern (the delimiter regex) and string, and it splits on every occurrence. Two behaviors from Python semantics to keep in mind:

  • Capturing groups in the pattern get included in the output. re.split(r'(,)', 'a,b') gives ['a', ',', 'b']. That's handy when you need the separators preserved, and confusing when you didn't ask for them.
  • maxsplit caps the number of splits. Default 0 = no limit; set it to 1 to split only on the first occurrence, which is a neat way to peel a header off "name,rest,of,line".

Inputs:

  • pattern - multiline field for the delimiter regex.
  • string - the text to split.
  • string_in - optional, overrides the widget, accepts a list of strings (each split independently).
  • flags - RE_FLAGS from the re.compile flags node (default IGNORECASE on).
  • maxsplit - INT, min 0, default 0 (unlimited).

The parts output is a list of strings. The status readout tells you "Split into N parts" or "No split", so you can confirm the delimiter actually matched before wiring anything downstream.

Why you'd reach for it

ComfyUI strings come from all over - prompts, filenames, metadata blobs, multi-line widget text - and they rarely arrive with a single clean separator. One pattern like [,\s]+ collapses commas and runs of whitespace into one split point, giving you a clean tag list where a plain split node would hand you ["", "cat", " dog ", ""]. It's also the right tool for splitting a batch of file paths out of a multi-line filename string before feeding them to an image loader.

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 model downloads; light pure-Python deps handled by Manager.

The gotcha

The included-captured-groups rule is the one that bites. If your delimiter pattern uses parentheses and your output suddenly has extra entries that look like the separators themselves, that's the feature working as Python documented it. Use non-capturing groups (?:...) if you want to group alternation without emitting the separator. And remember maxsplit=1 for "split on the first match only" - it's the difference between peeling one header and fragmenting everything.

Categoryovum/regex

Inputs (5)

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.
maxsplitoptINT0Maximum number of splits to perform. 0 means no limit.

Outputs (1)

NameTypeDescription
partsSTRING