🐟String Matcher
A regex routing table that turns text into typed decisions
- match_value
- value
🐟String Matcher is a tiny lookup table with regex - you give it a list of pattern:value rules, feed it a string, and it hands back the value of the first rule that matches. On its own that's a routing node; pair it with StringConverter and it becomes a decision engine for your workflow: "checkpoint name contains anime → use these settings," "prompt says photoreal → bump the CFG," that kind of thing. ComfyUI workflows are full of places where you want conditional behavior, and this is the cheap, dependency-free way to get it.
The rule format
The condition_list is a multiline string, one condition:value per line:
.*anime.*:anime_style
.*photoreal.*:photoreal_settings
E:\\models:windows_path
The condition side is a regular expression, and it's anchored for a full match - re.match(f"^{cond}$", ...). So .*anime.* matches anything containing "anime", while v\d\.\d matches only a version-looking string and nothing else. First matching rule wins, top to bottom; if a pattern is malformed regex, the node falls back to plain exact matching on that line instead of dying.
The inputs that matter
- condition_list - your rules. This is the whole game.
- match_value - the input to test. Optional
*type, converted to string for matching, so you can throw in a number or a filename. - target_type - what to do with the matched value:
STRING(default),INT,FLOAT,BOOL,LIST(comma-split), orDICT(JSON). This is the same conversion menu asStringConverter, folded into the match step. - default_value - returned when nothing matches, or when
match_valueis left unplugged. Empty string by default.
One output, value, typed per target_type.
Honest notes
Two behavior details worth knowing. First, if match_value is None (not wired), the node skips matching entirely and returns default_value - so an unplugged input isn't an error, it's a fallback. Second, if the matched value fails to convert - say you matched abc and asked for INT - you get a raised exception with a [String Matcher] Error converting ... message, which will stop your run. It's loud on purpose; don't ask for DICT on a rule that might match non-JSON.
The classic use: route on model filenames. Wire a model or LoRA name in, write rules like .*flux.*:flux_config, .*sdxl.*:sdxl_config, and drive a downstream switch or a StringConverter feeding sampler settings. It's the pack's most "workflow-logic" node - everything else here is about formatting or translating text; this one makes decisions.
Installing
ComfyUI Manager, search "ComfyUI-String-Helper", install, restart. Or:
cd ComfyUI/custom_nodes
git clone https://github.com/liuqianhonga/ComfyUI-String-Helper.git
Pure stdlib for this node (re, json) - the pack's translators/chardet deps install alongside but aren't used here.
Gotcha
Remember the anchor. People write rules from the README's examples and then wonder why train doesn't match a path containing train - because the pattern is anchored, you need .*train.* unless you really do mean exact equality. Sloppy regex here is the #1 source of "why is my rule never firing."
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| condition_list | STRING | — | |
| target_type | COMBO | STRING | 6 options: STRING, INT, FLOAT, BOOL, LIST, DICT |
| match_valueopt | * | — | |
| default_valueopt | STRING | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| value | * | — |