Nodes/VLM_nodes/Text Replace
ComfyUI Node Runs on cloud

Text Replace

Text Replace

By gokayfem·Created 3 years ago·Updated 9 days ago· 583
Text Replace
    • text
    • replacement_count
    • diagnostics_json
    text
    search
    replacement
    modeLiteral
    case_sensitivetrue
    max_replacements0
    if_not_foundKeep text

    Find-and-replace is the most taken-for-granted text operation in existence, and in ComfyUI it's usually done with regex nodes that silently do nothing when your pattern doesn't match. VLMTextReplace does the operation properly: literal or regex substitution, case sensitivity control, a hard cap on replacements, and - the part that saves real debugging time - explicit behavior when the search string isn't found.

    You reach for it whenever a model's output needs a surgical fix: strip a prefix the model keeps prepending, rename a label across a report, normalize a value, scrub a specific token before it reaches an API or a downstream parse. The pack's text toolkit is dependency-free, so this is a plain-Python find-and-replace that works anywhere.

    Inputs that matter

    • text - what you're editing.
    • search - the literal string or regex to find.
    • replacement - what replaces it (regex capture groups work in regex mode, \1 and friends).
    • mode - Literal or Regular expression. Literal is the safe default; switch to regex when you need patterns.
    • case_sensitive - on by default. Turn off for "replace regardless of case."
    • max_replacements - caps how many matches get replaced; 0 replaces every match.
    • if_not_found - Keep text (default) or Error. This is the underrated one: Error turns "my pattern silently matched nothing" into an immediate, loud failure instead of a wrong-looking downstream result.

    Outputs

    • text - the result.
    • replacement_count - exactly how many replacements happened. Wire this into a conditional or use it to confirm the operation did what you expected.
    • diagnostics_json - the operation's details for inspection.

    The replacement_count output is the quiet superpower. "Did my substitution actually fire?" is a question every automation has, and most find-and-replace tools make you eyeball the output. Here it's a number you can check programmatically.

    Install

    Part of ComfyUI VLM Nodes (gokayfem/ComfyUI_VLM_nodes). ComfyUI Manager → search "VLM Nodes", or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/gokayfem/ComfyUI_VLM_nodes
    python -m pip install -r ComfyUI/custom_nodes/ComfyUI_VLM_nodes/requirements.txt
    

    Run with ComfyUI's Python; the repo won't touch torch. No models, no downloads.

    Gotchas

    Regex mode is Python regex - if your workflow expects JavaScript or shell semantics, escape patterns will differ. And a subtle one: in Literal mode, the search is a literal string, so characters like * or ( are treated as plain text. That trips people coming from regex-first tools more than anything else here. When in doubt, check mode before wondering why nothing matched.

    CategoryVLM Nodes/Text/Transform

    Inputs (7)

    NameTypeDefaultDescription
    textSTRING
    searchSTRING
    replacementSTRING
    modeCOMBOLiteral2 options: Literal, Regular expression
    case_sensitiveBOOLEANtrue
    max_replacementsINT00–10000000 replaces every match.
    if_not_foundCOMBOKeep text2 options: Keep text, Error

    Outputs (3)

    NameTypeDescription
    textSTRING
    replacement_countINT
    diagnostics_jsonSTRING