Nodes/ComfyUI-RvTools_v2/Replace String
ComfyUI Node

Replace String

Full regex power for your prompts and filenames

By r-vage·Created about a year ago·Updated 5 months ago· 23
Replace String
    • STRING
    String
    Regex
    ReplaceWith

    Most "replace text" nodes in ComfyUI are dumb find-and-replace. This one is Python's re.sub wearing a node costume - which means you get the whole regular-expression language for free, including backreferences and capture groups. If you've ever wanted to strip every parenthetical from a prompt, collapse whitespace, or swap _ for spaces in a filename, this is the node that makes it a one-liner.

    How it works

    Under the hood it's literally re.sub(Regex, ReplaceWith, String). You give it:

    • String - the text to operate on.
    • Regex - the pattern to match. It's a Python regex, so \d+, [0-9], (.*?) and friends all work.
    • ReplaceWith - the replacement. Backreferences like \1 refer back to capture groups in the pattern.

    The output is the transformed string. That's the entire node, and honestly that's all it needs to be.

    Where it earns its keep

    Three quick wins:

    • Clean a messy prompt: Regex \s+, ReplaceWith collapses runs of whitespace into single spaces.
    • Strip tags: Regex \(.*?\), ReplaceWith empty removes every parenthetical (a common way to scrub weight syntax or emojis before sending a prompt somewhere that hates them).
    • Fix filenames: Regex _+, ReplaceWith - gives you hyphens instead of underscores, or vice versa.

    Because the output is a plain STRING, you can chain this node with others in the pack - feed it into a Merge Strings node, a text switcher, or straight into a CLIP Text Encode for prompts that get cleaned on the way through.

    Installing

    cd ComfyUI/custom_nodes
    git clone https://github.com/r-vage/ComfyUI-RvTools_v2
    

    Restart ComfyUI, or install via ComfyUI Manager by searching "ComfyUI-RvTools_v2". Nothing extra to download - regex is built into Python.

    The gotchas

    The trap is forgetting that an invalid or malformed regex throws a Python error and kills the whole queue, not just this node. ( with no closing ) is a classic. There's no friendly error message - you get a red node and a traceback, and you'll know instantly. Also note the case: the inputs are String, Regex, ReplaceWith exactly as written; if a shared workflow shows them lowercase, it's from the older v1 RvTools pack whose repo is gone, and you're looking at a node that can't be installed anymore. Finally, this pack is deprecated in favor of ComfyUI_Eclipse - fine to keep using, but worth knowing where the future of these nodes lives.

    Category🫦 RvTools II/ Text

    Inputs (3)

    NameTypeDefaultDescription
    StringSTRING
    RegexSTRING
    ReplaceWithSTRING

    Outputs (1)

    NameTypeDescription
    STRINGSTRING