Nodes/zsq_prompt/Option String
ComfyUI Node

Option String

Search-and-replace for your prompts, regex included

By windfancy·Created 2 years ago·Updated 5 months ago· 2
Option String
    • string
    input
    modeReplace
    str1
    str2

    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 of str1 for str2. The everyday mode: turn red hair into blonde 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 str1 as a regex pattern and str2 as 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 prefer masterpiece - 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, then str1, then str2. There's no separator choice beyond a comma, so if you need a different delimiter, do it in Replace afterward or use ConnectionString from the same pack.
    • A bad regex in Regular mode throws - the node doesn't swallow errors. Keep str1 valid or it'll halt the graph.
    • str2 is always required, even in modes where it might feel optional (Replace with empty str2 = 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.
    CategoryZSQ/Stinrg

    Inputs (4)

    NameTypeDefaultDescription
    inputSTRING
    modeCOMBOReplace3 options: Replace, Connection, Regular
    str1STRING
    str2STRING

    Outputs (1)

    NameTypeDescription
    stringSTRING