Simple Pattern Replace (WLSH)
Lightweight wildcards for your prompt text
- string
If you ever used Automatic1111's wildcard syntax - {brown|blonde|black} hair, randomly picking one option from a list every generation - this node is that same idea rebuilt for a ComfyUI graph, just wired a bit differently. Instead of curly braces embedded in your prompt text, you get a placeholder token and a separate list of options fed in as their own input, which fits ComfyUI's node-and-wire style better than trying to cram everything into one string.
How it works. You write your prompt normally, but drop in a placeholder - pattern, defaulting to $var - wherever you want a random substitution. Separately, list_string holds your options as a delimited list (comma by default, but delimiter lets you pick something else specifically so you can use commas inside your options without them being read as separators). The node picks one entry from that list at random - seeded by seed, so the same seed gives you the same pick reproducibly - and drops it in wherever pattern appears in input_string. One specific behavior worth knowing because it's easy to assume otherwise: if your placeholder shows up more than once in the input text, each occurrence gets its own independent random pick, not the same value copy-pasted everywhere. Want the same random pick reused across the prompt instead? You'd need to only place the token once and build your prompt around that, since the node doesn't offer a "reuse the first pick" mode.
Inputs: input_string (your prompt, with the placeholder embedded), list_string (your options, delimited), pattern (the placeholder token, default $var), delimiter (default comma), and seed (for reproducible randomness). Output: string - the finished text, ready to feed into a CLIP text encode node.
Installing it
ComfyUI Manager: search "wlsh_nodes" or "WLSH Nodes", install, restart. Manual: cd ComfyUI/custom_nodes && git clone https://github.com/wallish77/wlsh_nodes, then restart ComfyUI.
Common issues
The most common trip-up is forgetting the multiple-occurrence behavior above - if you expected one random word to replace every instance of $var consistently and instead got a different word at each spot, that's the node working as designed, not a bug. The other one is delimiter collisions: if your option list itself contains commas (say, you're listing multi-word phrases with commas inside them) and you left delimiter at its comma default, the node will split in the wrong places - switch delimiter to something that doesn't appear inside your actual options, like a pipe or semicolon. And obviously, if pattern in your input_string doesn't exactly match what you typed into the pattern field (including case), nothing gets replaced - the substitution is a literal string match, not a fuzzy one.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| input_string | STRING | — | |
| list_string | STRING | — | |
| pattern | STRING | $var | — |
| delimiter | STRING | , | — |
| seed | INT | 00–18446744073709550000 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| string | STRING | — |