String Replace
DF_String_Replace – ComfyUI Node from Derfuu_ComfyUI_ModdedNodes
- TEXT
DF_String_Replace does find-and-replace on text mid-graph - swap out a placeholder token in a templated prompt, strip a trigger word programmatically, or clean up text coming out of another node before it hits your CLIP encoder. It's one of the string-handling nodes in Derfuu_ComfyUI_ModdedNodes, a math-and-utility pack that's been part of ComfyUI since 2023, back before ComfyUI had many built-in ways to manipulate text inside a workflow rather than just typing a final prompt into a box.
Inputs and output
Four required inputs:
- Text - the
STRINGyou're operating on - Pattern - what to search for
- Replace_With - what to substitute it with
- Mode -
StrictorRegEx
One output: TEXT (a STRING), with every match of Pattern in Text swapped for Replace_With.
The Mode setting is the one thing to get right before you use this node. Strict treats Pattern as a literal substring - it replaces exactly the characters you typed, nothing more, and every occurrence in Text gets swapped. RegEx treats Pattern as an actual regular expression, matching per standard regex syntax rather than literal text. If you just want plain find-and-replace - swap "cat" for "dog" everywhere it appears - stick with Strict. Reach for RegEx only when you genuinely need pattern matching (wildcards, character classes, that kind of thing), and be aware that if your Pattern happens to contain characters that mean something special in regex - parentheses, brackets, a bare period - RegEx mode will interpret them as regex syntax instead of literal characters, which is a common source of "why didn't this match" confusion if you meant it literally.
Where it fits
This shows up in prompt-templating workflows: a base prompt string with a placeholder like {subject} that gets swapped for a value computed or randomized elsewhere in the graph, or a cleanup step stripping out something you don't want (a stray trigger word, an unwanted tag) before the final prompt goes to the encoder. It pairs naturally with DF_String_Concatenate when a workflow is assembling a prompt from several pieces rather than a single static text box.
Installing
The whole pack installs together - no single-node install. Through ComfyUI Manager: search Derfuu_ComfyUI_ModdedNodes, install, restart ComfyUI. Manually:
cd ComfyUI/custom_nodes
git clone https://github.com/Derfuu/Derfuu_ComfyUI_ModdedNodes
then restart. No models, no unusual dependencies.
Troubleshooting
If it doesn't show up in the node menu right after installing, restart the server and hard-refresh your browser tab - that resolves the large majority of "installed but not visible" cases and isn't specific to this pack.
If a replacement isn't matching the way you expect, check Mode first - the most common mistake is leaving it on RegEx while typing a plain literal pattern that happens to contain a regex-special character, which silently changes what actually gets matched. Switch to Strict if you don't specifically need pattern matching.
This is also one of the areas of the pack worth being cautious about long-term. Derfuu's string-handling nodes specifically have a documented history of disappearing across updates - a longtime user of the pack described its "pre text" and "app text" nodes getting deleted outright on an update rather than kept as a labeled legacy version, breaking downloaded workflows that used them with no warning beforehand. If a workflow you're relying on uses string nodes from this pack, be aware an update could remove or rename what you're depending on; check the GitHub repo before updating if the workflow matters to you.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| Text | STRING | — | |
| Pattern | STRING | — | |
| Replace_With | STRING | — | |
| Mode | COMBO | 2 options: Strict, RegEx |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| TEXT | STRING | — |