ComfyUI Node

Text Replacer

Batch-fix your prompts before the model sees them

By logicalor·Created 9 months ago·Updated 9 months ago· 1
Text Replacer
  • pairs
  • result
  • pairs
  • changes_log
  • replacement_count
input_text
use_regexfalse
case_sensitivetrue
replace_alltrue

Text Replacer is the half of the comfyui_multi_replace pack that actually does the work. Its sibling, Find/Replace Pairs, just stores your rules; this node applies them to a string and hands you the cleaned result. If you're normalizing prompt text before it reaches the text encoder - stripping trailing commas, swapping model-specific tokens, fixing the classic "replace underscores with spaces" dance - this is the node that makes it a set-and-forget part of the graph.

It's pure string surgery, and it runs entirely upstream of conditioning, so it costs you nothing at generation time. No model, no sampler, no VRAM. Just str.replace and re.sub under the hood.

How it works

Give it a FR_PAIRS object from Find/Replace Pairs plus some text, and it walks the pairs list in order, applying each find pattern to the running result. Order matters here: pair 3 sees the text after pairs 1 and 2 already changed it, so a rule like "fix typo, then uppercase" works exactly as written - but swap the order and you'll get different output.

A few behaviors worth knowing, all straight from the source:

  • Regex mode (use_regex) runs patterns through re.sub/re.findall. A bad pattern won't crash your workflow - it's caught and written into the changes log instead.
  • Case-insensitive plain-text mode internally escapes the pattern with re.escape, so you can't accidentally trigger regex behavior when you didn't ask for it.
  • replacement_count is the number of matches found. One subtlety: when replace_all is off, it caps at 1 per pair - it counts pairs where a replacement happened, not literal occurrences.

The inputs and outputs

  • pairs (required) - the FR_PAIRS object, which only comes from Find/Replace Pairs. Nothing else in the ecosystem speaks this type.
  • input_text (required) - the string to transform. Multiline, and defaults to empty, so if you forget to connect it you'll get an empty result and no error.
  • use_regex - off by default. Flip it on and your find patterns become regular expressions.
  • case_sensitive - on by default. This is the #1 "why didn't it match" trap; flip it off and "flux" will match "FLUX".
  • replace_all - on by default; turn it off to change only the first occurrence.

Four outputs: result (the transformed text - wire this into your prompt/text node), pairs (passed through untouched so you can chain replacers or reuse the same set), changes_log (a human-readable 'foo' -> 'bar' (2x) list of what changed), and replacement_count.

Installing it

One pack, one install, both nodes:

cd ComfyUI/custom_nodes
git clone https://github.com/logicalor/comfyui_multi_replace

or grab "Multi-Replace" through ComfyUI Manager. Then restart. No pip dependencies, no model downloads - the requirements file says "no additional dependencies required beyond ComfyUI," and it means it.

Troubleshooting

If nothing changes, check in this order: the find field on the source pair is non-empty (empty find patterns are skipped entirely), case_sensitive matches your text's casing, and - if you're in regex mode - that you didn't mean a literal dot when you typed one, because in regex . matches any character. If a regex genuinely fails, it won't crash; read the changes_log output and the error will be sitting there. And remember the chaining trick: pairs passes through every replacer, so you can run a second Text Replacer pass with different toggles over the same rules without rebuilding anything.

Categorytext/replace

Inputs (5)

NameTypeDefaultDescription
pairsFR_PAIRSFind/Replace pairs from the FindReplacePairs node
input_textSTRING
use_regexoptBOOLEANfalseTreat find patterns as regular expressions
case_sensitiveoptBOOLEANtrueWhether replacements are case-sensitive
replace_alloptBOOLEANtrueReplace all occurrences (vs only first)

Outputs (4)

NameTypeDescription
resultSTRINGThe text after all replacements have been applied
pairsFR_PAIRSThe find/replace pairs (passed through for chaining)
changes_logSTRINGLog of all replacements made
replacement_countINTTotal number of replacements performed