D2 Regex Switcher
The node behind per-checkpoint quality tags
- combined_text
- prefix
- suffix
- index
Regex Switcher is the node that powers the D2 pack's headline trick: a workflow that automatically picks the right quality tags based on which checkpoint family you're using. Pony models want score_9, score_8_up up front; Illustrious and others want a different set; and you don't want to hand-swap that text every time you change checkpoints.
Here's the idea. You give it a target string (say, the prompt), plus a lookup table of regex→output pairs. It searches your text with each regex in order and, on the first match, outputs that pair's text. No match? It falls back to a default output. Same general shape as A1111's wildcard-ish switching, done with regex so the matching can be loose.
The inputs that matter
text- the string being searched. Typically your prompt, wired in from a primitive or the checkpoint's trigger text.regex_and_output- the pair table. Format is regex,--, output, repeated:
A pair with an empty regex line is the default output (used when nothing matches).pony -- score_9, score_8_up, source_anime, -- -- highres, high quality,pre_delim/suf_delim- the separator between your prefix/suffix and the matched output:Comma,Line break, orNone.prefix/suffix- optional text stitched onto the front and back of the result.text_check- a scratch field for testing your regexes against before you commit.
Outputs: combined_text (prefix + separator + matched output + separator + suffix), prefix and suffix (passthroughs), and index - the 0-based position of the matching rule, or -1 when nothing matched. That index is genuinely useful: it lets downstream nodes branch on which family you're in, not just the text.
The mechanism, worth knowing
It's first-match-wins with re.search and case-insensitivity. The order of your pairs is the priority order - put the most specific regex first, or the generic one will eat the match. The default table in the node already demonstrates the pattern: match pony → pony quality tags, else → generic highres tags. Watch that the empty-regex default can be anywhere; the parser treats a pair with an empty regex line as the fallback.
Installing
Ships in the D2-nodes-ComfyUI pack - install the pack, not the node.
- ComfyUI Manager → search "D2-nodes-ComfyUI" → Install → restart.
- Or
cd ComfyUI/custom_nodes && git clone https://github.com/da2el-ai/D2-nodes-ComfyUIand restart.
Dependencies are just piexif and charset-normalizer, no model downloads. Pack gotcha: v32.0.0+ requires the newer ComfyUI V3 schema - older installs should pin a pre-32.0.0 release.
Where people get burned
Regexes are permissive by default. pony will match anywhere in the text, including inside a tag like ponytail - use anchors or word boundaries if that bites you. Also remember the -- split: if your output text legitimately contains --, it'll break the table. Keep outputs clean and put anything fancy in prefix/suffix. And if you're coming from D2 Regex Replace thinking this swaps text inside the prompt, it doesn't - this one selects whole output blocks, which is exactly what quality-tag switching needs.
Inputs (8)
| Name | Type | Default | Description |
|---|---|---|---|
| text | STRING | — | |
| regex_and_output | STRING | pony -- score_9, -- -- highres, high quality, | — |
| pre_delim | COMBO | 3 options: Comma, Line break, None | |
| suf_delim | COMBO | 3 options: Comma, Line break, None | |
| show_text | COMBO | 2 options: False, True | |
| text_check | STRING | — | |
| prefixopt | STRING | — | |
| suffixopt | STRING | — |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| combined_text | STRING | — |
| prefix | STRING | — |
| suffix | STRING | — |
| index | INT | — |