Nodes/comfyui-adaptiveprompts/πŸ” Prompt Replace πŸ”
ComfyUI Node

πŸ” Prompt Replace πŸ”

Search and replace where both sides can be dynamic prompts

By AlectricitiΒ·Created 12 months agoΒ·Updated 23 days agoΒ· 87
πŸ” Prompt Replace πŸ”
  • context
  • prompt
  • context
β—„stringβ€”β–Ί
β—„target_stringβ€”β–Ί
β—„replace_stringβ€”β–Ί
β—„seed0β–Ί
β—„limit0β–Ί
β—„categorywildcardsβ–Ί

A normal find-and-replace node is static - you type a fixed search string and a fixed replacement, and it does the same swap every run. PromptReplace wires the replacement side into the Adaptive Prompts wildcard engine, so instead of always replacing "fox" with "cow," you can replace it with whatever {1-2$$ and $$__animal__} rolls that particular time - a different, freshly-generated substitution on every match.

How it works

string is your source text. target_string holds the search terms - one per line, so you can search for several different keywords in a single pass rather than chaining multiple replace nodes. For each match found, replace_string gets evaluated fresh as its own dynamic prompt (brackets and wildcards resolved), so two occurrences of the same search term in your source text can end up replaced with two different results, not a single cached substitution copied everywhere. category picks which wildcards subfolder replace_string's wildcard calls draw from, and limit caps how many replacements happen in total if you don't want every match touched.

The inputs and outputs that matter

  • string - the text to search and replace within.
  • target_string - search terms, one per newline-separated line (not comma-separated - easy to get backwards if you're used to commas elsewhere in the pack).
  • replace_string - the replacement, itself a dynamic prompt that re-rolls per match.
  • seed - controls the dynamic-prompt rolls in replace_string.
  • limit - cap on total replacements.
  • category - wildcards folder for replace_string to pull from.
  • Optional context in, output context out - chain it like the other generator-family nodes if you need variable state to survive through the replacement.
  • Output: prompt - the resulting text after all replacements.

How to install it

Search comfyui-adaptiveprompts in ComfyUI Manager, or install manually:

cd ComfyUI/custom_nodes
git clone https://github.com/Alectriciti/comfyui-adaptiveprompts

Restart ComfyUI. Nothing extra to download - it's the same lightweight text-processing pack as every other node here.

Common issues & troubleshooting

Multiple search terms aren't being found. target_string splits on newlines, not commas - if you typed fox, dog on one line expecting two separate search terms, the node is reading that as a single literal search string "fox, dog" instead. Put each term on its own line.

Every match got the same replacement text. That would mean replace_string isn't actually dynamic (no brackets or wildcard calls in it) - a plain literal string will of course replace every match identically, which is correct behavior, just maybe not what you meant. Add {a|b|c} or a __wildcard__ call if you want per-match variety.

Replacements aren't happening at all. Double check limit isn't set to something smaller than the number of matches you expected, and confirm category points at a wildcards folder that actually contains whatever file replace_string references - a missing wildcard file in a non-default category folder falls back to the global wildcards/ folder, per the pack's general behavior, but only if the fallback file exists there too.

Categoryadaptiveprompts/generation

Inputs (7)

NameTypeDefaultDescription
stringSTRINGThe original string
target_stringSTRINGThe keywords to replace, separated by newlines. This can be done with prompts via {1-2$$ $$__wildcard__}
replace_stringSTRINGThe string or wildcard to be replaced with. Each replacement action will re-roll the wildcard
seedINT00–18446744073709550000β€”
limitINT0β€”
categoryCOMBOwildcardsSelect which wildcards folder to use. Create alternate folders named 'wildcards_*' (eg. 'wildcards_fresh') inside the package root. defaults to the global '/wildcards/ if a file is missing'
contextoptDICTβ€”

Outputs (2)

NameTypeDescription
promptSTRINGβ€”
contextDICTβ€”