Nodes/Quality of Life Nodes for ComfyUI/Special Character Replacer (Soze)
ComfyUI Node

Special Character Replacer (Soze)

Turn any string into a safe filename

By SozeInc·Created 2 years ago·Updated 5 days ago· 10
Special Character Replacer (Soze)
    • STRING
    input_string
    replace_chars"-;:/\|<>?}{[]()=+*^&%#!~`._,' @$
    replace_with
    strip_newlinestrue
    max_length0

    The default replace_chars value on this node is basically a wanted poster for every character that breaks a filename somewhere: quotes, slashes and backslashes, brackets, punctuation, even the space and the @/$. That list tells you exactly what this node is for - take arbitrary text (a prompt, an LLM-generated caption, anything you didn't type by hand into a filename field) and turn it into something safe to drop straight into a path or filename without ComfyUI or your OS choking on it.

    How it works

    input_string gets scanned for every character present in replace_chars, and each match gets swapped for replace_with. There's also a newline-stripping toggle and an optional length cap, so the whole node reads as a one-stop "make this text filesystem-safe" pass.

    The inputs and output that matter

    • input_string - the raw text to clean up.
    • replace_chars - the full set of characters to strip, defaulting to "-;:/\|<>?}{[]()=+*^&%#!~._,' @$`. Fully editable if you want to keep or add specific characters.
    • replace_with - what each matched character becomes. Default is an empty string, meaning matched characters just vanish; set it to _ if you'd rather see them replaced than deleted outright.
    • strip_newlines - on by default, and sensibly so, since filenames can't contain line breaks anyway.
    • max_length - truncates the result to this many characters. It defaults to 0, which in a numeric field like this almost always means "no limit" rather than "cut to zero" - but if you're actually relying on a length cap, set it explicitly rather than trusting the default's meaning. 255 is the safe universal filename length if you need a number to reach for.

    Output is a single STRING - the cleaned text, ready for a filename prefix or path segment.

    A concrete before/after, with defaults untouched: feed it A woman's "portrait", cinematic style (highly detailed). and you get back Awomansportraitcinematicstylehighlydetailed - every quote, comma, apostrophe, and parenthesis is gone, sure, but notice the words have also run together. That's because the default replace_chars includes a plain space, not just punctuation. It's easy to miss that on a quick read of the default value, and it's worth knowing before you point this at anything you want to stay readable.

    Installing it

    ComfyUI Manager: search ComfyUI_Soze. Manual: cd ComfyUI/custom_nodes && git clone https://github.com/SozeInc/ComfyUI_Soze.git, pip install -r ComfyUI_Soze/requirements.txt, restart. Pure string handling, no dependencies.

    Common issues

    The space-in-the-default-list behavior above is the single most common surprise with this node - if you want words kept separate in the output, either edit replace_chars to drop the space, or set replace_with to _ so spaces (and every other matched character) turn into underscores instead of disappearing.

    This pairs directly with the pack's own Save Image With Absolute Filename - run your prompt text through this node before it lands in filename_prefix. If a saved filename still contains a character you expected stripped, check that it's actually present in replace_chars: the default set is generous but not exhaustive, and it's your list to extend if you hit something it missed.

    Categorystrings

    Inputs (5)

    NameTypeDefaultDescription
    input_stringSTRING
    replace_charsSTRING"-;:/\|<>?}{[]()=+*^&%#!~`._,' @$
    replace_withSTRING
    strip_newlinesBOOLEANtrue
    max_lengthINT00–1000000

    Outputs (1)

    NameTypeDescription
    STRINGSTRING