MD: String Logic (Router)
Route your ComfyUI graph on prompt content with MD String Logic
- result_bool
- processed_string
- uppercase
- lowercase
The name undersells it. MD String Logic is billed as a text checker, but the thing you'll actually use it for is routing - "if the prompt mentions a city, send it down the hires path, otherwise keep the fast path." In ComfyUI you can't write if statements, so you fake them with a boolean and a switch node. This node produces the boolean.
How it works
It runs your two strings through a seeded wildcard expander first, then evaluates them. So both input_string and match_string support {A|B} syntax, and the seed input makes the pick reproducible - same seed, same expansion, which matters when you're trying to debug a routing rule.
The match itself has six operation options: Contains, Equals, Starts With, Ends With, Not Contains, and Regex Match (for patterns like ^\d+). Because match_string accepts comma-separated targets, you also get a match_mode to decide how multiple patterns combine: Any (OR) passes if at least one hits, All (AND) needs every one, None (NOR) passes when none do. case_sensitive defaults to False, so "Drum" and "drum" are the same word unless you tell it otherwise.
The inputs and outputs that matter
You'll set four things: input_string, match_string, operation, and match_mode. The seed only matters if wildcards are in play. That's it - the whole node is this.
The first output, result_bool, is the one you wire into a router or switch node. The other three are freebies: processed_string is the wildcard-expanded version of your input (handy if you just want a deterministic random pick), and uppercase / lowercase are exactly what they say.
Installing it
It ships in the MD Nodes pack:
cd path/to/ComfyUI/custom_nodes
git clone https://github.com/MDMAchine/ComfyUI_MD_Nodes.git
cd ComfyUI_MD_Nodes
pip install -r requirements.txt
Or search MD_Nodes in ComfyUI Manager and restart. Fair warning: this pack's requirements.txt pulls the whole audio stack (librosa, pedalboard, pyloudnorm…) even if you only want a logic node. It installs fine, just takes a while.
Gotchas
A bad regex doesn't crash anything - the code catches the error and returns False, which is good behavior but easy to misread as "the rule is wrong." And note that regex matching folds case according to your case_sensitive flag rather than through lowercasing, so Regex Match behaves slightly differently from the plain text operations. One more thing: the output is a plain ComfyUI BOOLEAN, so it works with any switch node you already have - you're not locked into MD's switch nodes to use it.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| input_string | STRING | TEXT TO ANALYZE • Purpose: The primary source text you want to check. • Support: Resolves {A|B} wildcard syntax. | |
| match_string | STRING | PATTERN(S) • Purpose: The specific word or regex you are looking for. • Note: Separate multiple target words with commas. | |
| operation | COMBO | Contains | LOGIC OPERATION • Purpose: How to evaluate the match. • Note: Regex Match allows advanced patterns (e.g. ^\d+). |
| match_mode | COMBO | Any (OR) | MULTI-PATTERN LOGIC • Purpose: Determines routing if multiple comma-separated patterns are provided. • Any (OR): True if at least ONE matches. • All (AND): True only if ALL match. |
| case_sensitive | BOOLEAN | false | CASE SENSITIVE • If False, 'Drum' is equal to 'drum'. |
| seed | INT | 00–9007199254740991 | SEED • Determines the random choice if wildcards {A|B} are used in the text. |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| result_bool | BOOLEAN | — |
| processed_string | STRING | — |
| uppercase | STRING | — |
| lowercase | STRING | — |