Nodes/ComfyUI_StringEssentials/String Multi Replace
ComfyUI Node

String Multi Replace

The find-and-replace ComfyUI was missing

By bradsec·Created 2 years ago·Updated 2 months ago· 36
String Multi Replace
    • modified_string
    input_string
    replacement_pairs
    replacement_delimiter::
    match_casefalse
    match_whole_stringfalse
    preserve_punctuationtrue
    remove_extra_spacestrue
    sort_by_lengthtrue
    use_regexfalse

    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::replace per 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, cat replaces the cat inside concatenate. 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) and remove_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_string defaults 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 fox clobbering red fox), but if you're deliberately chaining, turn sort_by_length off.
    • Backslashes in replacements are literal. A replacement like C:\1 is 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.

    Categoryutils/StringEssentials

    Inputs (9)

    NameTypeDefaultDescription
    input_stringSTRINGThe string to process
    replacement_pairsSTRINGEnter replacement pairs (one per line). Format: 'search<delimiter>replace'. Default delimiter is ':' (colon)
    replacement_delimiterSTRING::Character(s) that separate search and replace strings. Default is two '::' (colons)
    match_caseBOOLEANfalseWhen enabled, matching is case-sensitive.
    match_whole_stringBOOLEANfalseWhen enabled, only whole-word matches are replaced, not substrings inside other words.
    preserve_punctuationBOOLEANtrueWhen enabled, punctuation marks adjacent to matched text are preserved
    remove_extra_spacesBOOLEANtrueWhen enabled, collapses repeated spaces and trims the result after replacement.
    sort_by_lengthBOOLEANtrueWhen enabled, longer search strings are replaced first to prevent substring clobbering. Disable for input-order replacement.
    use_regexBOOLEANfalseWhen enabled, search strings are treated as regex patterns instead of literal text

    Outputs (1)

    NameTypeDescription
    modified_stringSTRING