Nodes/APZmedia Naming Tools/APZmedia String Stripper
ComfyUI Node

APZmedia String Stripper

Pull EP01-SH010 out of ACME-EP01-SH010-beauty without breaking a sweat

By APZmedia·Created 2 years ago·Updated 5 months ago· 8
APZmedia String Stripper
    • result
    • matched
    input_text
    mode
    patternproject-episode-shot-pass
    terms_to_keepshot
    output_delimiter-

    The flip side of the naming problem: once you've named files by convention, you eventually need to un-name them - extract the shot out of the filename, pull the version out of the path, rip the SKU out of a product render. APZmedia String Stripper is the APZmedia Naming Tools node for exactly that, and it's designed to sit right after APZmediaLoadImageWithFilename: feed it the filename_without_ext output, define the pattern, and get back just the segment you need.

    You get five inputs: input_text, mode (Simple or Regex), pattern, terms_to_keep, and output_delimiter. Two outputs: result (STRING) and matched (BOOLEAN). The clever bit is how forgiving it is, so let's walk the two modes.

    Simple mode is the one you'll use 90% of the time. You write the pattern with your actual delimiter - project-episode-shot-pass - and the node auto-detects the delimiter from the pattern's first non-alphanumeric character, splits both the pattern and the input on it, and maps slot names to values. Set terms_to_keep to episode,shot with output_delimiter of - and ACME-EP01-SH010-beauty becomes EP01-SH010. If the segment counts don't match (your input has four parts but the pattern expects five), it passes the original string through unchanged and sets matched to False, so the rest of your graph doesn't explode.

    Regex mode is for when your naming has grown teeth: supply a pattern with capture groups and reference them by number or name. ^(.+?)-v(\d+)-(.+)$ with terms_to_keep of 1,2 turns hero_shot-v003-final into hero_shot-v003. Named groups work too - terms_to_keep: ver with (?P<ver>\d+). Invalid regex or an optional group that didn't match lands you back in passthrough-with-matched: False.

    That matched output is the safety rail, and it's worth actually using: gate downstream nodes on it, or at least log it, so a filename you weren't expecting doesn't silently feed garbage onward. The other detail people trip on: output_delimiter is independent of the source delimiter, so you can extract with - and rejoin with _. And multiple kept terms come back in the order you listed them, not the order they appear in the filename.

    Install

    ComfyUI Manager → search "APZmedia Naming Tools". Or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/APZmedia/ComfyUI-APZmedia-cleanName-from-string
    cd ComfyUI-APZmedia-cleanName-from-string
    pip install -e .
    

    Restart and find it under APZmedia. No model downloads, no heavy dependencies - unidecode is the pack's only extra and this node is pure standard-library re. This is one of those small nodes that looks trivial until you realize you've been doing this by hand for an afternoon.

    CategoryAPZmedia

    Inputs (5)

    NameTypeDefaultDescription
    input_textSTRING
    modeCOMBO2 options: Simple, Regex
    patternSTRINGproject-episode-shot-pass
    terms_to_keepSTRINGshot
    output_delimiterSTRING-

    Outputs (2)

    NameTypeDescription
    resultSTRING
    matchedBOOLEAN