Nodes/CRT-Nodes/Advanced String Replace (CRT)
ComfyUI Node

Advanced String Replace (CRT)

Bulk find-and-replace with a stopword safety net

By PGCRT·Created 2 years ago·Updated 7 days ago· 129
Advanced String Replace (CRT)
    • STRING
    source
    to_replace
    replace_with
    exclude_wordsa an the and but or for nor so yet to in on at with by from of about as through over under i you he she it we they me him her us them my your his its our their is are was were be been being have has had do does did will would shall should can could may might must if then else when where why how what who whom which whose that this these those not no never always often sometimes usually one some any every each many much few more most up down out off mr mrs ms dr prof etc ie eg

    Every prompt-cleanup pass eventually runs into the same problem: you want to strip or swap a handful of words out of a batch of captions or prompts, but a naive find-and-replace also mangles the connective tissue - the "a", "the", "and", "with" that hold a sentence together. This node is CRT's answer to that: a text-replace tool that ships with a giant built-in exclusion list so your sweep doesn't eat the glue words along with the target ones.

    What it's for

    If you're doing anything caption-adjacent - cleaning WD14/BLIP tags before training, swapping a character name across a batch of stored prompts, stripping a recurring artifact word out of a dataset - you need something more surgical than ComfyUI's plain string-replace primitives. Advanced String Replace gives you a multiline block of terms to hunt for, one replacement to swap them all with, and a protected list of common words it won't touch even if they happen to match. It's a text node, so it slots in wherever a STRING output is expected: feeding a CLIPTextEncode, a save-with-metadata node, or another text node downstream.

    The inputs and outputs that matter

    Four fields, all required:

    • source - the multiline text block you're operating on. Your prompt, caption, or batch of text.
    • to_replace - multiline, one or more words/phrases to find in source.
    • replace_with - a single string that every match gets swapped for. Note there's only one replacement slot - this isn't a per-word mapping table, it's "find any of these, replace all of them with this."
    • exclude_words - multiline, and it ships pre-populated with a genuinely long list of English stopwords (articles, pronouns, conjunctions, prepositions, modal verbs, days-of-week abbreviations like "mr", "dr", "etc") right out of the box. Going by the default, the intent is a protected list - words here don't get touched by the replace pass even if you also listed them in to_replace.

    Output is a single STRING - the transformed text, ready to wire into whatever needs it.

    One honest gap: the schema doesn't expose whether matching is case-sensitive, whole-word-only, or substring-based, and the pack's README doesn't spell it out either. If your replace pass is behaving oddly on partial-word matches or capitalization, that's the first thing to test empirically rather than assume.

    Installing it

    This node ships inside the broader CRT-Nodes pack from PGCRT (CRYPT_EXE on Reddit/GitHub) - a large, actively maintained suite covering loaders, savers, FX, audio, sampling, and logic utilities, currently around 100+ node registrations. You don't install anything separately for this one node; you get the whole pack.

    ComfyUI Manager - search CRT-Nodes, install, restart.

    Manual:

    cd ComfyUI/custom_nodes
    git clone https://github.com/PGCRT/CRT-Nodes.git
    pip install -r requirements.txt
    

    Restart ComfyUI.

    The base requirements (opencv-contrib-python, scipy, ultralytics, color-matcher, spandrel, pedalboard, wordcloud, librosa, imageio-ffmpeg) cover the whole pack, not just this node - Advanced String Replace itself is pure Python string handling and doesn't pull in anything heavy on its own.

    Common issues

    • Missing node after install - CRT-Nodes is a kitchen-sink pack with several conditional nodes (the audio transcript node needs whisper/torchaudio, the Flux.2 Tiny VAE nodes need diffusers, etc.). If one of those optional imports fails at startup, the pack keeps loading everything else and just quietly drops the affected nodes. Advanced String Replace has no such dependency, so if it's missing, check your console log for an import error on the pack as a whole rather than assuming this specific node is broken.
    • Replacement not happening where you expect - since the exact matching rule (case, word boundaries) isn't documented, test with a short source string first before trusting it on a large batch.
    • replace_with feels too blunt for multi-term cleanup - remember it's one replacement for every term in to_replace. If you need different words mapped to different replacements, you'll need to chain multiple copies of this node rather than expecting a lookup table.
    CategoryCRT/Text

    Inputs (4)

    NameTypeDefaultDescription
    sourceSTRING
    to_replaceSTRING
    replace_withSTRING
    exclude_wordsSTRINGa an the and but or for nor so yet to in on at with by from of about as through over under i you he she it we they me him her us them my your his its our their is are was were be been being have has had do does did will would shall should can could may might must if then else when where why how what who whom which whose that this these those not no never always often sometimes usually one some any every each many much few more most up down out off mr mrs ms dr prof etc ie eg

    Outputs (1)

    NameTypeDescription
    STRINGSTRING