ComfyUI Node

Regex Split String

Regex Split String — carve text up at the pattern boundaries

By SeanScripts·Created 2 years ago·Updated 2 years ago· 79
Regex Split String
    • STRING
    pattern
    string
    flagsM

    Regex Split String cuts a string apart at every place a pattern matches, returning the pieces as a list. If your model output is "item1, item2, item3" and you want the three items separately, this is the node - a delimiter that's a regex instead of a fixed character, which is what makes it more flexible than the plain split you might expect to find.

    Inputs: pattern (the boundary to split on), string (the text to cut up), flags (default "M" - the pack's letter flags, a/i/l/m/s/u/x). Output is a STRING list of the pieces.

    How it works

    Python's re.split, with the flag letters translated to real regex flags (m = multiline, i = ignore-case, etc.). Split on \s+ to break on any whitespace run. Split on ,\s* for comma-separated values with optional spaces. Split on \n+ for lines. The pattern itself is discarded - only what's between the matches survives, so don't put capture groups in the pattern expecting them in the output (with a capture group, re.split actually does include the captured separator as an extra element - one of those Python behaviors you learn the hard way).

    Where it fits

    It's a natural cleanup stage for the pack's captioning: a model's answer often comes back as a loose list ("apples, bananas, oranges"), and splitting it lets you process each item individually or feed pieces into other nodes. Combined with Select Index or Join String from the same pack, it turns a wall of text into structured data you can actually route.

    Install

    Ships with the SeanScripts pack - ComfyUI Manager search ComfyUI-PixtralLlamaVision, or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/SeanScripts/ComfyUI-PixtralLlamaMolmoVision
    

    Restart after installing. No extra dependencies.

    Troubleshooting

    • Separators show up in the output - you used a capture group in the pattern. Remove the parens.
    • Split on nothing / too much - a pattern that matches zero-width positions (like \b or ^ in multiline) splits at every boundary; usually a symptom of the wrong pattern for the job.
    • Empty pieces in the list - consecutive delimiters produce empty strings ("a,,b" split on ,["a", "", "b"]). Filter them downstream or tighten the pattern.

    Simple, predictable, and useful the moment model output stops being one clean sentence. Split first, think later.

    CategoryPixtralLlamaVision/Utility

    Inputs (3)

    NameTypeDefaultDescription
    patternSTRING
    stringSTRING
    flagsSTRINGM

    Outputs (1)

    NameTypeDescription
    STRINGSTRING