rsplit (from data list)
Rsplit (from data list) — split from the end, when the tail is what matters
- STRING
split and rsplit answer the same question from opposite directions. split cuts a string into parts starting from the left; rsplit starts from the right. When does that matter? When the interesting part of your string is at the end, and you want to peel it off without computing how many parts come before it. rsplit (from data list) is the version that hands you a native ComfyUI data list of strings as its output.
The killer use is path and filename work with maxsplit=1: rsplit("/", 1) on a path splits it into "everything before the last slash" and "the final segment" - you get the folder and the filename without counting slashes. Same trick for the last comma in a data line or the last . before an extension.
How it works
Python's str.rsplit(sep, maxsplit), splitting from the right. Two behaviors to know:
- If
sepis empty (the default here), it becomesNone, which means "split on any run of whitespace" - spaces, tabs, newlines, with consecutive whitespace collapsing so you don't get empty tokens. maxsplitdefaults to-1(no limit). Set it to a small number to only split off that many parts from the end.
"a,b,c,d".rsplit(",", 2) → ["a,b", "c", "d"] - from the right, at most two splits: the last comma peels off "d", the next one peels off "c", and the leftmost element keeps everything that wasn't split. With maxsplit=1, the same string gives ["a,b,c", "d"] - the tail peeled off cleanly, which is the version you want for "split the last field off a line".
Inputs and outputs
string- required, the text to split.sep- optionalSTRING, default"". Empty means split on whitespace runs; otherwise split on that exact separator.maxsplit- optionalINT, default-1. Cap on the number of splits from the right;-1means no cap.
Output is a data list of STRING - each part is an individual value, so ComfyUI processes them one at a time and you can wire the output straight into per-item nodes.
Installing it
Ships in the Basic data handling pack by StableLlama. ComfyUI Manager, search "Basic data handling", install, restart. Manual route:
cd ComfyUI/custom_nodes
git clone https://github.com/StableLlama/ComfyUI-basic_data_handling
Pure Python, zero dependencies, no downloads. Under Basic/STRING in the menu.
Common issues
The data-list-vs-LIST distinction is the whole reason there are two rsplit nodes. This one emits a native data list, where each item gets processed individually by whatever you connect. If you wanted the parts kept together as one LIST variable, grab rsplit (from LIST) instead - the inputs are identical, only the output container differs. Separator behavior trips people too: with sep empty you get whitespace splitting that collapses runs (so "a b" → ["a", "b"], never ["a", "", "b"]), but with an explicit separator like ",", empty tokens are kept - "a,,b".rsplit(",", 1) → ["a,", "b"]. And remember with maxsplit=1 from the right, the big remaining chunk stays in the first output slot.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| string | STRING | — | |
| sepopt | STRING | — | |
| maxsplitopt | INT | -1 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| STRING | STRING | — |