String Compare
Turn any text check into a yes/no your graph can act on
- BOOLEAN
Once you've got strings flowing through a graph - a prompt, a filename from a loader, a tag from a metadata bundle - you'll want to ask questions about them. Does this filename say "4k"? Does this prompt mention the character? Is this sampler name one of the two I actually use? String Compare is the node that turns those questions into a BOOLEAN output you can drive a switch with.
It takes a string, a match value, a comparison mode, and returns a clean boolean. The trick, and the part people miss, is how the comparison dropdown changes what "match" means. It's a DYNAMIC combo, so the available modes are exact, contains, starts with, ends with, and regex. Exact is full-equality - the default - while contains does a substring search, and regex runs match as a regular expression. That last one is genuinely useful: a single regex like ^\d{3,4}x can collapse a whole tree of contains checks into one node.
The inputs that matter
- string - the text you're testing.
- match - what to compare against. Here's the trap: an empty match always returns
False, even incontainsorregexmode. It's in the tooltip, but people still hit it - if you leavematchblank "because I just want a true," you get a false, forever. Type something. - comparison - exact / contains / starts with / ends with / regex.
- case_sensitive - off by default, and that's worth knowing: comparisons are case-insensitive out of the box, so "4K" and "4k" match. Flip this on if casing actually matters to you.
- negate - inverts the result. Useful when you want "anything except X" without swapping branches downstream.
Output is a single BOOLEAN. Wire it into any of this pack's switches - String Switch, Signal Switch, Input Switch - or into the boolean AND/OR/NOT nodes to build bigger conditions. It composes like a logic gate because it is one.
How it behaves under the hood
The implementation is refreshingly honest: non-regex modes lowercase both strings unless case_sensitive is on, then do the obvious comparison. Regex mode uses re.search with the IGNORECASE flag unless you enable case sensitivity, and - a nice touch - if the regex is malformed it returns False instead of crashing your whole queue. So a bad regex fails safe: no error popup, just a False you'll probably spend a minute debugging anyway.
Installing it
Part of Nifty Nodes for ComfyUI (Stibo/comfyui-nifty-nodes). ComfyUI Manager → search "Nifty Nodes" → install, or:
cd ComfyUI/custom_nodes
git clone https://github.com/Stibo/comfyui-nifty-nodes
Restart after either. The pack is built on the v3 API (comfy_api.latest), so a recent ComfyUI is required - an old install won't load it at all. No extra dependencies or model files for the logic nodes.
Real-world wiring
The pattern that earns its keep: put Load & Resize Media (or any loader) in a workflow, take its output filename or is_video boolean, and use String Compare to branch. If the file is a video, route to a video pipeline; if the filename contains "upscaled", skip the upscale node. Combined with the pack's lazy Input Switch - which only evaluates the branch you actually take - this is how you build a workflow that adapts to whatever you drop into it.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| string | STRING | The string to test. | |
| match | STRING | The value to compare against. An empty match always returns False. | |
| comparison | COMBO | Comparison mode: exact = full equality, contains = substring search, starts/ends with = prefix/suffix, regex = regular expression. | |
| case_sensitive | BOOLEAN | false | When enabled, the comparison is case-sensitive. Default is case-insensitive. |
| negate | BOOLEAN | false | Invert the result — True becomes False and vice versa. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| BOOLEAN | BOOLEAN | — |