Nodes/ComfyUI-QING/文本切分丨规则
ComfyUI Node

文本切分丨规则

Four ways to cut a string, with the pieces on separate ports

By sheengoa·Created about a year ago·Updated 20 days ago· 16
文本切分丨规则
    • part_1
    • part_2
    • part_3
    • part_4
    • part_5
    • split_list
    • count
    text
    mode分隔符(delimiter)
    rule,
    maxsplit0
    strip_texttrue
    remove_emptytrue

    Comma-separated tags, a multi-line prompt, a chunked blob of text - ComfyUI is full of strings that want to be several strings. TextSplitter cuts them apart and hands you the pieces on individual ports, plus the whole list and a count. It's the data-tools workhorse of the QING pack, the one you reach for whenever "this one string is secretly many strings."

    Display name: "文本切分丨规则" ("text split / rule").

    The four modes

    The mode dropdown decides how the cutting happens, and rule provides the cutting tool:

    • 分隔符 (delimiter) - the default. Splits on whatever rule is, using Python's str.split(). Default rule is a comma, so "a,b,c" becomes three pieces.
    • 正则 (regex) - rule is a regular expression, split with re.split(). Power mode: split on "\n", on "[,;]", on any pattern you like.
    • 按行 (lines) - splits on line breaks. rule is ignored; perfect for dumping a multiline prompt into individual lines.
    • 固定长度 (fixed_length) - cuts the text into chunks of exactly N characters, where N is rule as an integer. This is the one mode where rule must be a positive integer.

    Two toggles clean up the output: strip_text (default on) trims whitespace off each piece, and remove_empty (default on) drops empty strings so you don't get ghost entries from trailing delimiters. maxsplit (default 0) limits how many splits happen - 0 means no limit, split everything.

    Inputs and outputs

    • text (required) - what to split. Multiline.
    • mode, rule, maxsplit, strip_text, remove_empty (required) - the split settings above.
    • Outputs: part_1 through part_5 (STRING, the first five pieces), split_list (STRING list, the complete result), and count (INT, number of pieces).

    The split_list output is the one to wire into a batch-style consumer that wants all the pieces; the individual part_1..5 ports are for when you know you only care about the first couple of chunks.

    The error handling (this is the quirk)

    TextSplitter doesn't throw exceptions at you - it returns an error as a string. If the regex is bad, part_1 comes back as a ❌ 正则错误: ... message, count is 0, and the rest are empty. Same for fixed_length with a non-positive rule (❌ fixed_length 模式下 rule 必须是大于 0 的整数). So check part_1 for the prefix, or test count, before trusting the output - a silent 0 with an error string in part_1 is easy to miss.

    Installing it

    TextSplitter ships in ComfyUI-QING:

    cd ComfyUI/custom_nodes
    git clone https://github.com/GAO-SHIQING/ComfyUI-QING
    cd ComfyUI-QING
    python install_dependencies.py
    

    Restart ComfyUI, or install "ComfyUI-QING" via ComfyUI Manager.

    Troubleshooting

    • part_1 starts with ❌. Read the message - it tells you whether the regex is broken or the fixed-length rule isn't a positive integer.
    • Pieces have extra spaces or empty entries. That's what strip_text and remove_empty are for; if you turned them off, you asked for the raw cuts.
    • count says 1 but I expected more. The delimiter mode with an empty rule doesn't split at all - the whole string stays intact.

    One node, four cutters. It won't win any beauty contests, but when you need "a, b, c" to become three wires, it's the fastest thing in the pack.

    CategoryQING/数据工具

    Inputs (6)

    NameTypeDefaultDescription
    textSTRING
    modeCOMBO分隔符(delimiter)4 options: 分隔符(delimiter), 正则(regex), 按行(lines), 固定长度(fixed_length)
    ruleSTRING,
    maxsplitINT00–100000
    strip_textBOOLEANtrue
    remove_emptyBOOLEANtrue

    Outputs (7)

    NameTypeDescription
    part_1STRING
    part_2STRING
    part_3STRING
    part_4STRING
    part_5STRING
    split_listSTRING
    countINT