Option String
Search-and-replace for your prompts, regex included
- string
Option String (OptionString) from the zsq_prompt pack is a text-transform node with three modes: find-and-replace, concatenate, and regex substitution. If you've ever wanted to strip a tag out of every prompt in a workflow, glue two prompt fragments together, or rewrite "red hair" → "blonde hair" across a batch, this is the node that does it without a Python script.
How it works
You feed it an input string (multiline, so whole prompt blocks work), two helper strings str1 and str2, and pick a mode:
- Replace - plain
input.replace(str1, str2). Swap every occurrence ofstr1forstr2. The everyday mode: turnred hairintoblonde hair, strip a quality tag, fix a typo across a prompt. - Connection - returns
input,str1,str2, i.e. it concatenates the input with both strings, comma-separated. Handy for appending style fragments onto a base prompt without writing out the whole thing. - Regular - treats
str1as a regex pattern andstr2as the replacement, run over the input. The power mode: match patterns instead of literal strings. The author's own example is replacing\d+(any number) with a label, so "shot at 50mm" can become "shot at NOMINAL" - or you can strip all numbers, or collapse repeated spaces, whatever your regex can express.
One output: the transformed string.
Inputs and outputs that matter
- input - the text to process (multiline).
- mode -
Replace/Connection/Regular. This is the input that decides everything. - str1 - the search term (or regex pattern in Regular mode).
- str2 - the replacement (or the extra strings to append in Connection mode).
- Output: string - the result.
Where it fits
- Prompt cleanup. A model page says use
(masterpiece:1.2)but you prefermasterpiece- a Replace node normalizes it before it hits the encoder. - Batch prompt templating. Keep a base prompt in a string node and use Connection to append per-style fragments on the way into the sampler.
- Regex sanitizing. Strip weighting syntax, remove numbers, or clean Danbooru-tag noise out of scraped text.
Note the honest caveat that applies to all prompt-string hacking: what these transformations do depends on the model you're feeding. On the CLIP-based SDXL lineage, (word:1.3) weights and comma-tags mean something; on newer LLM-encoded models they're largely inert. A Replace node that "strips weights" is only doing useful work if your model actually reads weights. Know your encoder, then transform.
Installing zsq_prompt
Shared pack install. ComfyUI Manager → search zsq_prompt → install, restart. Or:
cd ComfyUI/custom_nodes
git clone https://github.com/windfancy/zsq_prompt
Restart ComfyUI. Heavy shared deps (transformers, opencv-python, opencv-contrib-python, scikit-image, timm, onnx, ultralytics) come with the pack. If Manager flags "conflicting with zsq_prompt" on a workflow, that's dependency-overlap noise; only meaningful once the pack is actually installed. No model downloads needed.
Gotchas
- In Connection mode the order is fixed:
input, thenstr1, thenstr2. There's no separator choice beyond a comma, so if you need a different delimiter, do it in Replace afterward or useConnectionStringfrom the same pack. - A bad regex in Regular mode throws - the node doesn't swallow errors. Keep
str1valid or it'll halt the graph. str2is always required, even in modes where it might feel optional (Replace with emptystr2= delete the match; that works, just leave it blank).- Category note: the pack labels these nodes "ZSQ/Stinrg" - a typo, not a secret. You'll find them under the misspelled menu.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| input | STRING | — | |
| mode | COMBO | Replace | 3 options: Replace, Connection, Regular |
| str1 | STRING | — | |
| str2 | STRING | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| string | STRING | — |