Nodes/noEmbryo nodes/Regex Text Chopper /noEmbryo
ComfyUI Node

Regex Text Chopper /noEmbryo

Slice a prompt into parts without a dozen string nodes

By noembryo·Created 3 years ago·Updated 3 days ago· 37
Regex Text Chopper /noEmbryo
    • Part 1
    • Part 2
    • Part 3
    • Part 4
    • All parts
    text
    regex

    Regex is one of those things ComfyUI makes you work for. Want to pull a style tag out of a long prompt, split a metadata dump, or fish a seed out of a blob of text? Normally that's a math node, a few string operations, and a prayer. This little node from the noEmbryo pack compresses all of that into one box: give it text and a pattern, and it hands you back the matches on separate outputs.

    It's a niche tool - you won't use it in every workflow, but the day you need it, you need it badly and nothing stock does it. That's the whole pitch.

    How it works

    The mechanism is plain Python re.findall(pattern, text, re.MULTILINE) - no custom parsing, no magic. It runs the pattern against your text, collects every match, and routes the first four into the Part 1 through Part 4 outputs. All parts is every match joined together with blank lines, which is handy when you want the whole extraction as one string but don't know how many matches you'll get.

    Inputs and outputs

    • text - the string to parse. It's forceInput, so you can wire it straight from a CLIP Text Encode, a text box, or another node's output instead of typing into it.
    • regex - your pattern, entered as plain text. Python regex syntax applies.

    Outputs are Part 1, Part 2, Part 3, Part 4, and All parts - all STRING type, ready to feed into anything that accepts text.

    The traps, and they're real ones

    • It only returns the first four matches. Fifth match onward still shows up inside All parts, but Part 1–4 are capped. If you're extracting more than four things, wire the All parts output instead and split downstream.
    • Don't use capturing groups unless you mean it. re.findall returns tuples instead of plain strings when your pattern has () groups - so Part 1 might come out as ('a', 'b') rather than a. Use non-capturing groups (?:...) if you need grouping but want plain string matches.
    • A malformed pattern will error the node, not degrade. The code tries to be nice about this - there's a validity check that's supposed to catch bad patterns and fall back to emptying the parts. But the check compiles re.escape(your_pattern), which basically always succeeds because escaping makes any input valid. So that fallback is effectively dead code, and a genuinely broken pattern (say, an unmatched () throws a Python re.error and fails your whole queue. Validate your regex in a tester before you paste it in.
    • Zero matches are the real silent failure: four empty strings, and All parts is empty too. There's no visual signal, so if you get empties, first assume zero matches, then check the pattern syntax.

    Install

    Same as the rest of the pack: ComfyUI Manager → search "noEmbryo", or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/noembryo/ComfyUI-noEmbryo.git
    

    then restart. No dependencies, no models - the node ships in the pack's single nodes.py file and uses nothing but Python's built-in re module.

    Honestly? Most people reach for this once, get their parse working, and never look at it again. But the node sits in your menu forever, and the next time a prompt-generation node hands you a messy string you need to dissect, you'll be glad it's there.

    CategorynoEmbryo

    Inputs (2)

    NameTypeDefaultDescription
    textSTRINGThe text that we'll parse
    regexSTRINGThe RegEx pattern

    Outputs (5)

    NameTypeDescription
    Part 1STRING
    Part 2STRING
    Part 3STRING
    Part 4STRING
    All partsSTRING