Regex Match To Float
Pick a number based on what your text says
- FLOAT
A switch, not a parser
Regex Match To Float doesn't pull a number out of your text. It asks one yes/no question - does this regex pattern appear in this string? - and then hands back one of two floats you typed in. Match means output_on_match, no match means output_on_non_match. That's the whole node, and honestly that's fine.
It ships in db0's personal utility pack, so it's small, does one thing, and makes a couple of opinionated calls you should know about. (Same db0 who runs AI Horde and wrote the Civitai Helper extension - a real name in the scene, but this is his "custom nodes for my purposes" drawer, not a polished library.)
Why you'd bother
ComfyUI workflows are programs, and programs need branches. Most switch nodes route on numbers or booleans, but the decision in your head usually lives in a string: the prompt, a tag list, the output of an LLM node, a filename. Regex Match To Float is how you turn that text into a knob.
Reachable uses:
- Prompt mentions "night" → drop CFG to 4 or bump denoise to 0.6
- A tag list contains
1girl→ feed a different LoRA strength - Whatever your captioning/LLM node returned contains a marker → use a different upscale factor
Classic "wire a text decision into the sampler" glue.
How it works
Under the hood it's one re.search() call from Python's stdlib - no dependencies, no model files. The three optional toggles map straight onto regex flags: case_insensitive sets IGNORECASE, multiline sets MULTILINE, dotall makes . match newlines too.
The one that will trip you up: case_insensitive defaults to True. Most regex tools are case-sensitive by default; this one isn't. If "1Girl" shouldn't match 1girl, open the advanced inputs and switch it off.
The inputs that matter
- string (multiline) - the text being tested. A prompt, a tag list, anything.
- regex_pattern (multiline) - the pattern to search for. Remember, this is a substring search: pattern
foxmatchesthe quick brown fox. It is not a full-string match. If you want the whole string, anchor it:^fox$. - output_on_match / output_on_non_match - the two FLOAT values it can return. These are just pass-through values; it never extracts or transforms anything from the string.
- The three advanced booleans - set them once and forget them.
Output: a single FLOAT, whatever value matched the branch. Wire it into any float input in your graph - CFG, denoise, a LoRA strength, an upscale factor, a KSampler step count. Because it's just a number, it composes with everything.
Installing it
ComfyUI Manager → Install Custom Nodes → search "comfyui-db0-pack" → install, restart. Or the manual route:
cd ComfyUI/custom_nodes
git clone https://github.com/db0/comfyui-db0-pack
Restart ComfyUI. No extra Python packages, no model downloads - it's pure stdlib.
Gotchas
- Needs a recent ComfyUI. The pack is written against the newer declarative node API (
comfy_api), not the classic decorator style. If it fails to import, update ComfyUI first - older installs can't load it. - Bad regex = hard error. There's no try/except around
re.search, so a malformed pattern throwsre.errorand kills the workflow. Double-check your pattern, or test it in a scratch text editor first. - Case-insensitive by default (see above). It's the trap that wastes the most time.
^and$change meaning if you flipmultilineon - they start matching at every line boundary instead of the whole string's start/end.
It's a tiny node, so if you only need one comparison, a String-to-boolean conditional might do. But the moment you want to steer numeric settings off a string, this is the direct path.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| string | STRING | — | |
| regex_pattern | STRING | — | |
| output_on_match | FLOAT | — | |
| output_on_non_match | FLOAT | — | |
| case_insensitiveopt | BOOLEAN | true | — |
| multilineopt | BOOLEAN | false | — |
| dotallopt | BOOLEAN | false | When enabled, the dot (.) character will match any character including newline characters. When disabled, dots won't match newlines. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| FLOAT | FLOAT | — |