String Multi Replace
The find-and-replace ComfyUI was missing
- modified_string
Every text-wrangling workflow eventually needs a real find-and-replace, and core ComfyUI just doesn't give you one that handles a whole batch. String Multi Replace is the missing tool: you feed it a list of search::replace pairs, one per line, and it applies them all to your string. dog::cat turns "the quick brown fox" into a new sentence, and you can fix ten things at once.
It's built for the messiest realistic job: cleaning up LLM output. Ollama, Claude, and ChatGPT happily produce prompts and image descriptions full of vocabulary you don't want the sampler to see - "provided", "vibrant masterpiece", "highly detailed" - and they rarely use the same wording twice. One pass through this node normalizes all of it. Pair with String Strip for the deletions and String Preview to check your work, and you've got a full prompt-cleanup pipeline.
How it works
Each non-empty line is split on the replacement_delimiter (default ::). The left side is the search, the right is the replacement - and you can delete instead of replace by leaving the right side blank. The node builds a regex per pair and applies them in order. The two flags worth understanding are sort_by_length (on by default: longer searches run first so red fox matches before fox can eat it) and use_regex (off by default: searches are literal text, safely escaped, so [A1111:Forge:.5] and (word:1.2) survive untouched).
The inputs that matter
replacement_pairs-search::replaceper line. Blank right side = remove.replacement_delimiter- default::. If your search text contains::, change this (say, to=>).match_whole_string- default off here, which trips people up: with it off,catreplaces thecatinsideconcatenate. Flip it on for whole-word only.sort_by_length- longest-first (default) prevents substring clobbering; disable it to force pairs to run in the exact order you typed them, which lets you chain replacements deliberately.use_regex- treat searches as regex patterns. Handy for real pattern work; a bad pattern raises a clean error telling you which one failed and to disable the flag - not a bare traceback.preserve_punctuation(on) andremove_extra_spaces(on) keep prompt syntax intact and clean up the result.
Output: a single modified_string.
Installation
No dependencies, no model files. Via ComfyUI Manager: Manager > Custom Nodes Manager > search "ComfyUI_StringEssentials" > Install, restart. Or:
cd ComfyUI/custom_nodes
git clone https://github.com/bradsec/ComfyUI_StringEssentials.git
Restart, then it's under Add Node > utils > StringEssentials.
Gotchas
match_whole_stringdefaults to false on this node but true on String Strip. Same pack, opposite defaults - easy to assume they behave alike. Set it explicitly.- Longest-first ordering means your pairs don't run in the order you wrote them. Usually that's the correct instinct (it prevents
foxclobberingred fox), but if you're deliberately chaining, turnsort_by_lengthoff. - Backslashes in replacements are literal. A replacement like
C:\1is written out verbatim rather than being parsed as a regex group reference - a genuinely thoughtful touch for paths. - In regex mode, your search string is now real regex, so remember to escape literals; in literal mode everything is auto-escaped for you.
This is probably the node from the pack that people end up keeping even when they uninstall the rest. It's the one that makes LLM text actually usable.
Inputs (9)
| Name | Type | Default | Description |
|---|---|---|---|
| input_string | STRING | The string to process | |
| replacement_pairs | STRING | Enter replacement pairs (one per line). Format: 'search<delimiter>replace'. Default delimiter is ':' (colon) | |
| replacement_delimiter | STRING | :: | Character(s) that separate search and replace strings. Default is two '::' (colons) |
| match_case | BOOLEAN | false | When enabled, matching is case-sensitive. |
| match_whole_string | BOOLEAN | false | When enabled, only whole-word matches are replaced, not substrings inside other words. |
| preserve_punctuation | BOOLEAN | true | When enabled, punctuation marks adjacent to matched text are preserved |
| remove_extra_spaces | BOOLEAN | true | When enabled, collapses repeated spaces and trims the result after replacement. |
| sort_by_length | BOOLEAN | true | When enabled, longer search strings are replaced first to prevent substring clobbering. Disable for input-order replacement. |
| use_regex | BOOLEAN | false | When enabled, search strings are treated as regex patterns instead of literal text |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| modified_string | STRING | — |