Switch (Yogurt Nodes)
A regex-powered case statement for your workflow
- condition
- option1
- option2
- option3
- option4
- option5
- option6
- option7
- option8
- default
- data
ComfyUI's built-in "switch" is a binary if/else: one condition, two branches. Real workflows grow past that fast. YogurtSwitch is the pack's case statement - up to eight regex patterns, eight matching options, a fallback, and one output that routes your data based on which pattern the condition matches. If you've ever wanted "if the filename contains 'portrait', use this sampler config; if it says 'landscape', use that one; otherwise, the default," this is the node.
How it works
A condition input (typed *, though the tooltip describes it as "Input condition text," so treat it as text when writing your patterns) is matched against case1 through case8, each a STRING holding a regex. First match wins: whatever is wired into that case's matching optionN input (typed *, so it can carry numbers, strings, even images) is passed to the single data output. If nothing matches, the default input wins.
That's the whole mechanism, and it's more flexible than it looks. Because the cases are regexes, one case can cover a family of values - ^portrait matches "portrait_v2", "portrait_ultra", and half a dozen friends - instead of you writing an equality check per value.
A beginner's honest guide to the inputs
condition- the value you're routing on.case1–case8- regex patterns. Only the ones you actually use need filling; empty cases just never match.option1–option8- the payload for each case. Wire a value in for every case you've defined.default- whatdatabecomes when nothing matches. Set this. An unset default is the classic "it just outputs nothing" mystery.
One output: data. It's *-typed, so it connects almost anywhere.
Where it shines
Batch processing with mixed input. You're looping over a folder where some files are images and some are masks, and the routing decision ("send this one to the upscaler, that one to the inpaint path") is a filename pattern match. Or you have a YogurtStringLinesSwitch pulling model names out of a list, and the switch dispatches each name to its matching checkpoint config. It's the kind of node that turns a graph you babysit into a graph that routes itself.
Installing it
Part of the Yogurt Nodes pack (YogurtNodes/Logic), one install for all of them. ComfyUI Manager (search "ComfyUI-YogurtNodes") or:
cd ComfyUI/custom_nodes
git clone https://github.com/yogurt7771/ComfyUI-YogurtNodes.git
cd ComfyUI-YogurtNodes
pip install -r requirements.txt
Restart ComfyUI. No models, no keys.
Common issues
Regex mistakes are the main trap - a pattern like portrait matches anywhere in the string, but ^portrait anchors to the start, and forgetting the difference is how you get surprising routes. Test patterns in a regex tester before wiring them into a workflow you care about. Also note that "first match wins," so if two cases both match, the lower-numbered one takes it - order your cases from most specific to most general. And don't leave default empty; that's the silent no-output failure that makes you doubt the whole node.
Inputs (18)
| Name | Type | Default | Description |
|---|---|---|---|
| condition | * | Input condition text. | |
| case1 | STRING | the regex to match for case1. | |
| case2 | STRING | the regex to match for case2. | |
| case3 | STRING | the regex to match for case3. | |
| case4 | STRING | the regex to match for case4. | |
| case5 | STRING | the regex to match for case5. | |
| case6 | STRING | the regex to match for case6. | |
| case7 | STRING | the regex to match for case7. | |
| case8 | STRING | the regex to match for case8. | |
| option1opt | * | The data to return if case1 matches. | |
| option2opt | * | The data to return if case2 matches. | |
| option3opt | * | The data to return if case3 matches. | |
| option4opt | * | The data to return if case4 matches. | |
| option5opt | * | The data to return if case5 matches. | |
| option6opt | * | The data to return if case6 matches. | |
| option7opt | * | The data to return if case7 matches. | |
| option8opt | * | The data to return if case8 matches. | |
| defaultopt | * | The default option to switch to. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| data | * | — |