TOO Much Replace π
Five rules of cleanup for prompts and strings
- STRING
TOO Much Replace is a string cleaner: one input, up to five find-and-replace rules, one output. You drop a string in, tell it what to strip or rewrite, and it applies the rules in order. The name oversells it - it's five rules, not a hurricane - but five is exactly the right number for the job it's actually good at: scrubbing prompts and text before they go into a filename or metadata.
That's the real use case, and it pairs perfectly with this pack's saver. Grab your positive prompt with Extract Widget From Node, run it through Too Much Replace to delete the garbage tokens, then feed the result into the saver's naming. The classic move: in: (masterpiece, best quality) β out: (empty), which turns a filename like beautiful_landscape_(masterpiece,_best_quality).webp into beautiful_landscape.webp. Same trick for removing weight syntax, stripping duplicate tags, or rewriting a word you keep mistyping.
How it works. Each rule is a pair - input_N is the search text, output_N is the replacement. Rules run in sequence on the result of the previous one, and only rules with a non-empty search string do anything. Two important details. First, it's a literal search-and-replace (str.replace), not regex - so (masterpiece) means exactly that text with the parens. If you need regex, the pack's Preset Text node has regex-flavored presets instead. Second, the node declares IS_CHANGED so it always re-runs, which matters because it's often fed by live values (widget extraction) that the cache would otherwise miss. The trade-off: it keeps everything downstream of it dirty, so don't put it in front of a heavy sampler.
Inputs and outputs. Required: string (the multiline input) and five rule pairs - input_1/output_1 through input_5/output_5. Output is a single STRING. Leave unused rules empty; they're skipped.
Install.
cd ComfyUI/custom_nodes
git clone https://github.com/tetsuoo-online/Comfyui-TOO-Pack
or ComfyUI Manager β "Comfyui-TOO-Pack" β restart. No dependencies.
Where people get burned. Because rules apply in order, a later rule can undo an earlier one - if rule 1 turns masterpiece into art, and rule 2 removes the word art, you've removed your own fix. Order matters, top-down. And don't expect regex: paste \d+ and it will literally search for the characters backslash-d-plus, find nothing, and silently do nothing. For a cleanup step in a filename pipeline it's dependable and fast; just know its limits before you ask it for magic.
Inputs (11)
| Name | Type | Default | Description |
|---|---|---|---|
| string | STRING | Input string to process | |
| input_1 | STRING | Pattern to search for (rule 1) | |
| output_1 | STRING | Replacement value (rule 1) | |
| input_2 | STRING | Pattern to search for (rule 2) | |
| output_2 | STRING | Replacement value (rule 2) | |
| input_3 | STRING | Pattern to search for (rule 3) | |
| output_3 | STRING | Replacement value (rule 3) | |
| input_4 | STRING | Pattern to search for (rule 4) | |
| output_4 | STRING | Replacement value (rule 4) | |
| input_5 | STRING | Pattern to search for (rule 5) | |
| output_5 | STRING | Replacement value (rule 5) |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| STRING | STRING | β |