按序号提取分割文本🐠meeeyo.com
Grab the nth piece of a delimited string — forward or backward
- STRING
Comma-separated and pipe-separated data is everywhere in ComfyUI - a,b,c, 2|3|5, lines of a prompt list - and getting "just the third piece" out is a surprisingly common chore. SplitAndExtractText is the node for it: split your text on a delimiter, pick the piece at a given index, and return it. It even lets you count from the end, and optionally keeps the delimiter on the result.
The Chinese display name is 按序号提取分割文本 ("extract split text by sequence number"). It's part of ComfyUI_StringOps, and it's the direct sibling of TextToList - that one gives you the whole list, this one reaches in and grabs a single element.
How it works
Five inputs:
- input_text - the source.
- delimiter - what to split on. Default is the Chinese placeholder 分隔符 ("delimiter"), so change it. If you leave it empty, it splits on newlines instead.
- index - which piece, 1-based (default
1). Soindex = 2grabs the second piece. - order -
顺序(forward) or倒序(reverse). In reverse, index 1 is the last piece. - include_delimiter - if true, the result keeps the delimiters that flank it (the one before and after, where they exist).
So a,b,c with delimiter = ",", index = 2 gives b. With order = 倒序 (reverse), index = 1 gives c. With include_delimiter on and index = 2, you'd get ,b,.
Output is a single STRING. If the index is out of range, you get an empty string - not an error.
Where you'd use it
Parsing structured strings is the main game: pull the second item out of an Excel read, grab a value out of a URL-ish or config string, extract one field from a pipe-delimited row. The reverse mode is handy when you want "the last field" without counting how many there are - e.g. a filename that varies in length but always ends with a known suffix. And include_delimiter is there for when you're rebuilding a string and need to preserve the separators.
It chains naturally: ReadExcelData → this node → a specific value. Or TextToList upstream if you'd rather index a real list.
The traps
The delimiter default is a literal Chinese placeholder string - run it without changing it and you'll split on the text "分隔符" and get nothing. Also, pieces are stripped and blank pieces dropped from the result (via a splitlines() pass), so index positions may shift if your text has empty fields - a,,c won't necessarily give you "empty" at index 2; you may just get shifted content. If empty fields matter, TextToList is the more predictable splitter.
Installing it
Pack standard: ComfyUI Manager → ComfyUI_StringOps, or
cd ComfyUI/custom_nodes
git clone https://github.com/MeeeyoAI/ComfyUI_StringOps.git
Restart. Pure Python - no extra dependencies.
The honest take
A solid little extraction node with a genuinely useful reverse mode. It's not a regex engine and it fumbles on empty fields, but for "give me the nth field of this delimited string" it's the cleanest one-node answer in the pack. Remember to set the delimiter and you're done.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| input_text | STRING | — | |
| delimiter | STRING | 分隔符 | — |
| index | INT | 1 | — |
| order | COMBO | 顺序 | 2 options: 顺序, 倒序 |
| include_delimiter | BOOLEAN | false | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| STRING | STRING | — |