Nodes/ComfyUI-YCNodes/YC Text Bracket Replace
ComfyUI Node

YC Text Bracket Replace

Strip (parenthetical noise) out of your prompt — full-width brackets included

By yichengup·Created 2 years ago·Updated 4 months ago· 48
YC Text Bracket Replace
    • text
    text
    start_char(
    end_char)
    replace_with
    use_regextrue

    Prompts accumulate junk inside parentheses: (masterpiece), (best quality), legacy weighting like (dog:1.2), or notes you left yourself. YC Text Bracket Replace deletes or replaces everything between a start_char and end_char - default ( and ) - and it does it non-greedy, so each pair is handled independently and (a)(b) becomes just "" with both removed, not one mangled chunk.

    The genuinely thoughtful detail is that it also handles full-width CJK bracket pairs. If your prompt came from a Chinese model card or a Bilibili tutorial and has (这里) full-width parentheses, the node maps () to (), [] to [], {} to {}, and <> to <> and cleans those too. That's the kind of thing you only add if you actually hit it, and it tells you where this pack's author lives.

    How it works

    Regex under the hood: it escapes your delimiters and builds start + ".*?" + end (the .*? is what makes it non-greedy), then replaces matches with replace_with. use_regex defaults to true; flip it to false and it falls back to a manual find/replace loop, which is there for safety when your delimiter contains regex-special characters that escaping would mangle.

    The inputs that matter

    • text (multiline) - the prompt or string to clean.
    • start_char / end_char - defaults ( and ). Set them to [/] or {/} for other bracket styles.
    • replace_with - default empty, which deletes. Put a keyword here and every parenthetical gets swapped for it.
    • use_regex - on by default; leave it on unless something's misbehaving.

    Output is a single text string. Chain it between your text node and your CLIP encoder, or feed it the output of a wildcard/dynamic prompt node to normalize before encoding.

    Install

    From 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

    Non-greedy matching is great for (a)(b), but it means nested brackets ((outer (inner))) will match the innermost pair first and leave the outer one - run it twice if your prompts are deeply nested. And deleting every (word) unconditionally can remove useful emphasis if you're targeting a model that still respects (weight) notation. That's the real trap: on modern LLM-encoded models the parentheticals are largely dead weight anyway, so this is a cleanup win there - but if you're still on a model where weighting matters, set replace_with to a space or double-check what you're stripping.

    CategoryYCNode/Text

    Inputs (5)

    NameTypeDefaultDescription
    textSTRING
    start_charSTRING(
    end_charSTRING)
    replace_withSTRING
    use_regexoptBOOLEANtrue

    Outputs (1)

    NameTypeDescription
    textSTRING