文本切分丨规则
Four ways to cut a string, with the pieces on separate ports
- part_1
- part_2
- part_3
- part_4
- part_5
- split_list
- count
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
ruleis, using Python'sstr.split(). Default rule is a comma, so"a,b,c"becomes three pieces. - 正则 (regex) -
ruleis a regular expression, split withre.split(). Power mode: split on"\n", on"[,;]", on any pattern you like. - 按行 (lines) - splits on line breaks.
ruleis ignored; perfect for dumping a multiline prompt into individual lines. - 固定长度 (fixed_length) - cuts the text into chunks of exactly N characters, where N is
ruleas an integer. This is the one mode whererulemust 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_1throughpart_5(STRING, the first five pieces),split_list(STRING list, the complete result), andcount(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_1starts 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_textandremove_emptyare for; if you turned them off, you asked for the raw cuts. countsays 1 but I expected more. The delimiter mode with an emptyruledoesn'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.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| text | STRING | — | |
| mode | COMBO | 分隔符(delimiter) | 4 options: 分隔符(delimiter), 正则(regex), 按行(lines), 固定长度(fixed_length) |
| rule | STRING | , | — |
| maxsplit | INT | 00–100000 | — |
| strip_text | BOOLEAN | true | — |
| remove_empty | BOOLEAN | true | — |
Outputs (7)
| Name | Type | Description |
|---|---|---|
| part_1 | STRING | — |
| part_2 | STRING | — |
| part_3 | STRING | — |
| part_4 | STRING | — |
| part_5 | STRING | — |
| split_list | STRING | — |
| count | INT | — |