Extract Number (YC)
Pull the leading number out of a string — the tiny logic helper that saves a regex node
- number
Somewhere in your workflow there's a number trapped inside text: a seed that came out of a filename, a step count from an API response, a frame index from a label. Extract Number (YC) takes a string, finds the integer at the start of it, and hands you an INT. That's the whole job, and it's the kind of node that deletes the need for a dedicated regex node just to do one \d+ match.
The interesting design choice is that it only matches a number at the start of the string (^\d+). So "42_photo.png" → 42, but "photo_42.png" → nothing. That's a deliberate, strict rule - it makes the behavior predictable, and it means a filename scheme that puts the number first is exactly what this node expects.
How it works
It strips whitespace and runs one regex, ^\d+. If it matches, that's the output. If not - and this is the part that makes it useful in real graphs - it returns default_value (default 0) instead of failing. That turns it into a safe parser: an unparseable string degrades to a number your workflow can handle rather than throwing and killing the run.
The inputs
text(STRING) - whatever you're parsing.default_value(INT, default 0) - the fallback when no leading number exists.
Output is number, an INT. Wire it into a seed node, a math node, a batch index, or anywhere else an INT is expected.
Install
Part of ComfyUI-YCNodes. ComfyUI Manager → search "ComfyUI-YCNodes", or:
cd ComfyUI/custom_nodes
git clone https://github.com/yichengup/ComfyUI-YCNodes
Restart ComfyUI. Standard deps, no downloads. Found under "YCNode/Logic".
Gotchas
Three honest limits. It only reads the leading integer - decimals ("3.5x") truncate to the int part (3), and a leading letter means you get the default, so "v2_1280.png" returns 0, not 1280. It's INT-only; no floats out of this node. And because the fallback silently returns default_value, a parse that quietly yields 0 can masquerade as a real result - if your workflow branches on the number, make sure a 0 means something you intended. For anything that needs a number buried mid-string, this isn't it; that's a regex-node job.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| text | STRING | — | |
| default_value | INT | 0 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| number | INT | — |