Replace Prompt
Find-and-replace for your prompt, three rules at a time
- text
Every prompt goes through "swap X for Y" at some point: replace "woman" with "man", strip the "masterpiece" you inherited from a downloaded workflow, or re-roll a style word. Replace Prompt is that operation as a node - up to three pattern/replace pairs applied to an incoming prompt, with toggles for how strictly to match. It's the cleanup tool in ComfyUI-PromptWrapper, and it slots in anywhere a STRING flows.
How it works
The source is a thin wrapper over Python's re.sub. It takes the incoming prompt, and for each pair where the pattern isn't empty, runs string_replace(pattern, replace, text). The subtle bit people miss: the default matching is already case-insensitive regex - the helper builds re.IGNORECASE flags in every branch, and match_full / match_case / match_regex only shuffle which flags get applied, not whether regex is used. Practically, your pattern_A is always treated as a regex.
Inputs that matter
- prompt - force-wired input text.
- pattern_A / replace_A, pattern_B / replace_B, pattern_C / replace_C - three find-and-replace rules, applied in order A → B → C. Empty patterns are skipped.
- match_case - when on, matching becomes case-sensitive.
- match_regex - on by default in effect; with it off you still get regex behavior from the default flags, so treat patterns as regex regardless.
- match_full - the odd one out; despite the name it doesn't require whole-string matches, it just tweaks flags. Don't rely on it for "match only the whole prompt" semantics.
One text output with the replaced result.
Install
ComfyUI Manager → Custom Nodes Manager → search ComfyUI-PromptWrapper → Install → restart, or:
cd ComfyUI/custom_nodes
git clone https://github.com/clouddreamfly/ComfyUI-PromptWrapper
No dependencies, no models.
Where people get burned
Regex escaping is the whole story. Want to replace the literal (low quality:1.2)? The parentheses and colon are regex metacharacters - write \(low quality:1\.2\) or the match silently fails (or worse, matches something you didn't intend). Since matching is case-insensitive by default, a pattern like blue will also hit Blue and BLUE, which is usually what you want in a prompt but surprises people coming from a strict find-and-replace. And remember rules cascade: rule B operates on the output of rule A, so keep your patterns from colliding. If three rules aren't enough, the pack's Multi Replace Prompt gives you six pairs.
Inputs (10)
| Name | Type | Default | Description |
|---|---|---|---|
| prompt | STRING | — | |
| pattern_A | STRING | — | |
| replace_A | STRING | — | |
| pattern_B | STRING | — | |
| replace_B | STRING | — | |
| pattern_C | STRING | — | |
| replace_C | STRING | — | |
| match_full | BOOLEAN | false | — |
| match_case | STRING | false | — |
| match_regex | STRING | false | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| text | STRING | — |