Nodes/Basic data handling/split (data list)
ComfyUI Node

split (data list)

Split a string on a regex, and fan the pieces out

By StableLlama·Created about a year ago·Updated 16 days ago· 51
split (data list)
    • parts
    ◄string—►
    ◄pattern—►

    Plain string split breaks on one literal separator, and that's usually not what your data looks like. Your captions are separated by commas and newlines. Your filenames use -, _, and spaces. Your config dumps have arbitrary whitespace runs. This node is re.split() - split on a pattern - with the results returned as a data list, so each piece becomes its own item ComfyUI can process individually.

    That data-list output is the reason this variant exists alongside the "(LIST)" one. Split "red, green , blue" on \s*,\s* and you get red, green, blue as three separate items ready to flow into per-item slots - the difference between "I can batch these" and "I have one list variable I must index into." For turning messy delimited text into a fan-out of clean items, this is the node.

    How it works

    Straight re.split(pattern, string). Three behaviors to internalize:

    • The separator disappears. re.split(r"\s*,\s*", "a, b") → ["a", "b"]. If you want the separators kept, wrap the pattern in a group - re.split keeps captured separators in the output.
    • Empty pieces survive. Trailing separators, or a leading match, produce "" entries. "a,b," → ["a", "b", ""].
    • It's regex, so the split point can be a whole structure - "(\d+)" splits on every number, which is a genuinely useful trick for pulling text apart into alternating chunks.

    The class declares OUTPUT_IS_LIST, so the pieces come out as a data list - each string an individual item rather than one bundled LIST.

    Inputs and output

    • string - the text to split.
    • pattern - the regex separator.

    Output is a data list of STRINGs. No match at all just means the whole input comes back as a single-element list - which is correct behavior, though it surprises people expecting an error.

    Installing it

    Part of the Basic data handling pack by StableLlama:

    cd ComfyUI/custom_nodes
    git clone https://github.com/StableLlama/ComfyUI-basic_data_handling
    

    Restart, or grab it via ComfyUI Manager (search "Basic data handling"). Zero dependencies, no models - nothing at install to go wrong.

    Gotchas

    • Empty strings in the output are normal, not a bug. Filter them with a data-list filter node before they hit something that chokes on "".
    • If you're splitting on something you want to keep (like \n when rebuilding lines), wrap it in a group.
    • Greedy quantifiers in the separator pattern can merge or skip separators in surprising ways. Test the pattern on a scratch node with your real data before trusting a batch pipeline to it.
    CategoryBasic/STRING/regex

    Inputs (2)

    NameTypeDefaultDescription
    stringSTRINGThe text to split.
    patternSTRINGRegular expression pattern used as the delimiter.

    Outputs (1)

    NameTypeDescription
    partsSTRINGThe substrings between matches, as a data list.