Nodes/JSON Dynamic Loader/String Extract
ComfyUI Node

String Extract

Pull the one piece of a string you actually need

By ethanfel·Created 7 months ago·Updated 2 months ago· 2
String Extract
    • result
    • dirname
    • basename
    • extension
    text
    mode
    delimiter/
    index-1
    delimiter_2

    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 - split text on delimiter and take the part at index. Negative indices work, so index: -1 grabs the last segment - the classic way to get a filename from a full path.
      • between - return everything after delimiter up to delimiter_2. If delimiter_2 is empty, it takes everything from delimiter to the end.
      • filename_parts - skip the carving entirely; decompose text as 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.

    CategoryJSON Dynamic/string

    Inputs (5)

    NameTypeDefaultDescription
    textSTRING
    modeCOMBO3 options: split_take, between, filename_parts
    delimiteroptSTRING/
    indexoptINT-1-999–999
    delimiter_2optSTRING

    Outputs (4)

    NameTypeDescription
    resultSTRING
    dirnameSTRING
    basenameSTRING
    extensionSTRING