Nodes/ComfyCollectorNodes/String Extractor (CCN)
ComfyUI Node

String Extractor (CCN)

Rip one substring out of anything using bookends

By valkymaera·Created 4 months ago·Updated 10 days ago· 1
String Extractor (CCN)
    • before
    • middle
    • after
    input_string
    start_bookend
    end_bookend
    wide_bookendsfalse
    case_sensitivetrue

    You have a filename like sarah_sunset_2560x1440_seed42.png and you need the 2560x1440 out of it. Or a prompt that came with a metadata block you want to strip before re-encoding. String Extractor (CCN) is the tool for that specific, annoying job: you give it a start bookend and an end bookend, and it hands you back the text before, between, and after them - three outputs at once.

    Where this shines over a blunt string-replace or a manual split is that you never touch the rest of the string. Wire middle into whatever needs the extracted value and keep before/after for later, or ignore them. It's the sort of node that lives quietly in a corner of a workflow until a metadata format changes and you're glad you didn't hand-roll it.

    How it works

    The node splits the input into three segments around your two marker strings ("bookends"):

    • before - everything up to and including the start bookend
    • middle - everything strictly between the bookends (whitespace-trimmed)
    • after - everything from the end bookend onward, inclusive

    Two toggles control the matching. wide_bookends flips between "expand the middle" and "squeeze it." With it off (the default) the node uses the first start bookend and the last end bookend, so the middle is as big as it can be. With it on, it uses the last start and first end - the middle is minimized and guaranteed clean of bookend strings. For most one-off extractions the default is right; the wide mode matters when your bookend text appears multiple times and you want the innermost region.

    case_sensitive does what it says - the default is on, so flip it if your markers might vary in case.

    The failure handling is friendlier than most string nodes. If neither bookend is found, the whole input comes out as middle. If only one shows up, you still get sensible before/middle or middle/after instead of a crash.

    The inputs and outputs that matter

    • input_string - the text to search.
    • start_bookend / end_bookend - your markers. Leave one empty to split on just the other.
    • wide_bookends - default off; flip on to squeeze to the innermost match.

    Outputs: before, middle, after - all STRING. middle is the one you'll usually wire forward.

    How to install it

    Part of ComfyCollectorNodes, so one install covers this and every other CCN node. Use ComfyUI Manager (search ComfyCollectorNodes), or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/valkymaera/ComfyCollectorNodes.git
    

    Restart ComfyUI afterwards. No extra Python dependencies. Search the node menu for CCN to find the whole pack.

    Common issues

    The thing that trips people up is the bookend inclusivity. before includes the start marker and after includes the end marker, by design - so if you're building a new string from before + middle you'll get the start bookend back in there. And remember middle is trimmed, so if your extracted value legitimately needs leading or trailing spaces, this isn't the node for that.

    Also worth knowing: matching is plain substring matching, not regex. If your markers are close together or overlap, the middle just comes out empty rather than erroring - which is graceful, but means your bookends were wrong.

    CategoryCCN/String

    Inputs (5)

    NameTypeDefaultDescription
    input_stringSTRING
    start_bookendSTRING
    end_bookendSTRING
    wide_bookendsoptBOOLEANfalse
    case_sensitiveoptBOOLEANtrue

    Outputs (3)

    NameTypeDescription
    beforeSTRING
    middleSTRING
    afterSTRING