Regex Extract
Pull the numbers out of any text with one pattern — trigger words, sizes, seeds, you name it
- match
- count
Every so often your workflow hands you a blob of text that contains the one number you need - a resolution out of a filename, a seed out of a log, a trigger word out of a metadata dump. Regex Extract is the surgical tool for that: give it text and a pattern, and it returns the match. It sits at the boundary between "text in, text out" utilities and real data extraction, and it's the node that lets your graph react to what's written on a wire instead of what you typed into a widget.
It's built on Python's re module, so every pattern you already know works. The design has one genuinely smart convention: if your pattern contains a capture group - (\d+), say - the node returns the group, not the whole match. No group, and you get the full match. That single rule makes both "extract the number" and "extract the sentence" trivial with the same interface.
The inputs that matter
text- the source string.pattern- your regex. The capture-group rule above is the thing to remember.all_matches- the toggle that changes behavior completely. Off (default), you get the first match. On, every match is emitted as a separate list item - the output is declared as a list type, so downstream list-aware nodes can consume the whole set at once.case_insensitive,multiline,dotall- the standard flags, each applyingre.IGNORECASE,re.MULTILINE(so^/$match line boundaries), andre.DOTALL(so.matches newlines).default- what comes back when nothing matches, defaulting to an empty string. This is the underrated input: set a fallback and a missing match becomes a graceful default instead of a downstream error.
The outputs
match (STRING, list-capable) and count (INT) - the number of matches found. count is the sneaky useful one for conditional logic: combine it with MoonPack's Conditional Bypasser and your graph can branch on whether something was found at all.
Installing it
Part of the MoonPack pack:
cd ComfyUI/custom_nodes
git clone https://github.com/moonwhaler/comfyui-moonpack.git
or ComfyUI Manager → MoonPack → install, restart. Under MoonPack/string. No models, no extra Python dependencies.
The gotcha
Regex is a power tool and it will happily match more than you intended. The classic beginner mistake is (\d+) on a string that contains several numbers - you get the first one, and it's rarely the one you wanted. If you're extracting a specific field, anchor it: match the surrounding context (size: (\d+)x(\d+)) instead of a bare number class. And remember default: it's the difference between a silent failure and a workflow that keeps running.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| text | STRING | Source text. | |
| pattern | STRING | Regex pattern. Use a capture group to extract a substring. | |
| case_insensitiveopt | BOOLEAN | false | — |
| multilineopt | BOOLEAN | false | — |
| dotallopt | BOOLEAN | false | — |
| all_matchesopt | BOOLEAN | false | If true, every match is emitted as a separate item (OUTPUT_IS_LIST). |
| defaultopt | STRING | Returned when there is no match. |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| match | STRING | — |
| count | INT | — |