String Extract
Pull the one piece of a string you actually need
- result
- dirname
- basename
- extension
String Extract is the text-processing cousin of the pack's String Format: where Format builds strings up, Extract tears them down. It takes one string and gives you three ways to carve a substring out of it, plus a bonus filename decomposition that's handy in its own right. For anything involving parsed paths, shot names, or log-ish text, this is the node you didn't know you needed.
The mode that decides everything
text(STRING) - what you're extracting from.mode- one of three behaviors:split_take- splittextondelimiterand take the part atindex. Negative indices work, soindex: -1grabs the last segment - the classic way to get a filename from a full path.between- return everything afterdelimiterup todelimiter_2. Ifdelimiter_2is empty, it takes everything fromdelimiterto the end.filename_parts- skip the carving entirely; decomposetextas a path.
The supporting inputs only matter per mode: delimiter (default /) for split/between, index (default -1) for split_take, and delimiter_2 for between's end marker.
The outputs
Four STRING outputs - result, plus dirname, basename, and extension (the last three populated in filename_parts mode, and computed in the other modes too as a by-product). So in filename mode you get all four at once: result is the name without extension, dirname the folder, basename the full file name, extension the suffix without the dot. It's like getting the whole os.path toolbox on one node.
Edge cases are handled quietly rather than loudly: a split index that's out of range returns an empty string instead of crashing, and between with no match returns empty. That's friendlier than a hard failure, but it means an empty result can be a real empty string or a "didn't match" - check your delimiter if you're getting blanks.
Install
Part of ComfyUI-JSON-Dynamic. ComfyUI Manager → search JSON Dynamic Loader, or:
cd ComfyUI/custom_nodes
git clone https://github.com/ethanfel/ComfyUI-JSON-Dynamic.git
# restart ComfyUI
No dependencies.
When you'd use it
The killer use case is turning a full path into a filename you can feed to a LoadImage-style node, or stripping the extension off a sequence number to format it. If your workflow never parses strings, skip it - but the moment you're hand-building output/ paths and then fighting to get the basename back, this is the node that ends the fight.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| text | STRING | — | |
| mode | COMBO | 3 options: split_take, between, filename_parts | |
| delimiteropt | STRING | / | — |
| indexopt | INT | -1-999–999 | — |
| delimiter_2opt | STRING | — |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| result | STRING | — |
| dirname | STRING | — |
| basename | STRING | — |
| extension | STRING | — |