Nodes/ComfyUI-YCNodes/text keyword
ComfyUI Node

text keyword

Grab everything before (or after) a keyword — for filenames, tags, and prompt surgery

By yichengup·Created 2 years ago·Updated 4 months ago· 48
text keyword
    • processed_text
    textYour text here
    keywordkeyword
    modebefore
    case_sensitivetrue

    Text Keyword is a string slicer: give it a keyword and it returns everything before it (default mode) or everything after it. It's the kind of node you don't need often, and when you need it you need it right now - extracting the scene name from scene_beach_0123.png, pulling the category out of a booru-style tag string, or chopping a prompt at a marker you put there on purpose.

    It's honest plumbing. Most string-work in ComfyUI is done by regex nodes or concatenation, and this is a friendly wrapper around one find() call. There's a real niche for it in filenames: if you're auto-labeling batches, Load Images From Folder YC gives you the filename, and this node can peel the meaningful part off before you route it into a prompt.

    How it works

    It finds the first occurrence of keyword in text, then slices:

    • before - everything up to (not including) the keyword.
    • after - everything after (not including) the keyword.

    Both results get .strip()-ed, so stray whitespace around the cut doesn't survive. If the keyword isn't found, it returns the original text unchanged - a graceful "nothing to do" rather than an error. case_sensitive defaults to true; turn it off to match "BEACH" against "beach". The keyword itself is never included in the result.

    The inputs that matter

    • text (multiline) - what to cut from.
    • keyword - the boundary marker.
    • mode - before or after.
    • case_sensitive - on by default.

    Output is processed_text, a single string. The one thing to note: it finds the first occurrence only. If your keyword appears twice, you get the text before the first one, not between them.

    Install

    Part of ComfyUI-YCNodes. ComfyUI Manager → search "ComfyUI-YCNodes", or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/yichengup/ComfyUI-YCNodes
    

    Restart ComfyUI. Standard deps, no downloads. Under "YCNode/Text".

    Gotchas

    Because it returns the original text when the keyword is missing, a typo in keyword silently passes the whole string through - you'll see it in the result and wonder why nothing happened. Also the strip means leading/trailing spaces around your cut vanish; if you were counting on the whitespace as a separator, add it back or use after and check the result. For anything more complex than "cut at the first marker," you want a regex node - this one is deliberately simple, which is the point.

    CategoryYCNode/Text

    Inputs (4)

    NameTypeDefaultDescription
    textSTRINGYour text here
    keywordSTRINGkeyword
    modeCOMBObefore2 options: before, after
    case_sensitiveBOOLEANtrue

    Outputs (1)

    NameTypeDescription
    processed_textSTRING