Nodes/WAS Node Suite v3/Text Replace Words
ComfyUI Node Runs on cloud

Text Replace Words

Swap words and phrases across a whole batch of captions or prompts, such as every `a woman` or `woman` for `[trigger]`, and make sure each text holds a phrase. It matches whole words, keeps capitals, tidies the commas a deleted word leaves, and names the texts no rule matched.

By WASasquatch·Created 4 years ago·Updated 3 days ago· 1,900
Text Replace Words
  • text
  • names
  • text
  • texts
  • changed
  • unmatched
◄rules►
◄whole_wordstrue►
◄ignore_casetrue►
◄keep_capitalstrue►
◄tidytrue►
◄ensure►
◄ensure_atstart►
◄separator, ►
CategoryWAS Suite/Text/Search

Inputs (10)

NameTypeDefaultDescription
textSTRING,ARRAYThe captions or prompts to change, as `a woman on a beach`: a STRING list such as Load Text Batch's texts, a LIST, or one text typed here. Order is kept, so each text still pairs with its file name.
rulesSTRINGOne rule per line, as `a woman, the woman, woman -> [trigger]`: commas separate the finds, and nothing after the arrow deletes them, as `blurry ->`. Longer finds win. Lines starting with # and blank lines are skipped. Empty = no change.
whole_wordsBOOLEANtruetrue = `man` never matches inside `woman` or `manly`; false = finds match inside other words too. A find starting or ending in a symbol, such as `[trigger]` or `(red)`, matches wherever it stands.
ignore_caseBOOLEANtruetrue = `woman` also finds `Woman` and `WOMAN`; false = only the spelling typed. The ensured phrase is looked for the same way.
keep_capitalsBOOLEANtruetrue = `Woman` becomes `Person` and `WOMAN` becomes `PERSON`; false = every replacement as typed. A replacement not starting with a letter, such as `[trigger]`, is always written as typed.
tidyBOOLEANtruetrue = in each text a rule changed, doubled spaces, spaces before commas and the stray commas a deleted word leaves are cleared, so `a woman, , outdoors` becomes `a woman, outdoors`; false = only the replacements are made.
ensureSTRINGA phrase every text has to hold, such as `[trigger]`, added to each text that still lacks it after the rules. It is found the way the finds are. A blank text stays blank. Empty = nothing added.
ensure_atCOMBOstartstart = `[trigger], a woman on a beach`; end = `a woman on a beach, [trigger]`, placed before a closing full stop when the separator is a comma.
separatorSTRING, What joins the ensured phrase to the text: `, ` for tag captions, a space for prose, `\n` for a line of its own.
namesoptARRAY,STRINGThe file names that go with the texts, in the same order, such as from Load Text Batch. Used only to name texts in the report; unwired, texts are named by place, counting from 0.

Outputs (4)

NameTypeDescription
textSTRINGThe texts after the rules, one per text that came in and in the same order, so a node reading this runs once per text, such as a save writing each caption back under its own name.
textsARRAYThe same texts as one LIST, for the list nodes.
changedINTHow many texts a rule or the ensured phrase changed. 0 = the batch came through as it went in.
unmatchedINTHow many texts no rule matched, such as captions that never mention a woman for `woman -> [trigger]`. The report names each one; the ensured phrase may still have been added to them.