Text Replace
Text Replace
- text
- replacement_count
- diagnostics_json
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,\1and friends).mode-LiteralorRegular 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;0replaces every match.if_not_found-Keep text(default) orError. This is the underrated one:Errorturns "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.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| text | STRING | — | |
| search | STRING | — | |
| replacement | STRING | — | |
| mode | COMBO | Literal | 2 options: Literal, Regular expression |
| case_sensitive | BOOLEAN | true | — |
| max_replacements | INT | 00–1000000 | 0 replaces every match. |
| if_not_found | COMBO | Keep text | 2 options: Keep text, Error |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| text | STRING | — |
| replacement_count | INT | — |
| diagnostics_json | STRING | — |