Nodes/Comfyui-General-API-Node/Regex Extractor Pro (FeiMao-326)
ComfyUI Node

Regex Extractor Pro (FeiMao-326)

Pull hex colors, coordinates, numbers out of any LLM text

By FeiMao-326·Created 12 months ago·Updated 5 months ago· 0
Regex Extractor Pro (FeiMao-326)
    • text
    text
    regex(\d+)
    group_index1
    all_matchesfalse
    delimiter,

    LLMs love to bury the one number you need inside a paragraph of prose. You asked for a hex color and the model gave you "the primary accent is #7C3AED, a vibrant violet that pops against the dark background." Somewhere in there is the value that should drive your workflow - and this node is a precise scalpel for exactly that situation.

    How it works

    You give it text, a regex pattern, and a group_index, and it runs the pattern against the text. The default pattern (\d+) grabs the first run of digits, which is the right starting point for "extract a number" but almost never your final pattern. You'll want to swap in your own, like #?([0-9a-fA-F]{6}) for hex colors or -?\d+(?:\.\d+)? for coordinates.

    Three behaviors define it:

    • Capture groups are first-class. group_index (default 1, range 0–99) selects which group you want, so a pattern like (\d+)x(\d+) can return just the width or just the height. Group 0 gives the whole match.
    • all_matches toggles first-hit vs. everything. Off (default) returns only the first match. On, it returns every match joined by a delimiter (default ", "), which turns "find all the numbers in this text" into a one-liner.
    • Bad patterns fail softly. A syntax error in your regex returns the string Regex Error: ... as the output instead of crashing the graph. Missing group indexes return an empty string.

    The output is a single text string. There's no node-specific type or list output - which is the one thing to know before you lean on it: if you need a real list of matches, set all_matches and re-split, or grab the joined string and split it yourself.

    Where it fits

    The author's example is the classic one: pull a hex color out of a long LLM description and feed it into a color-driven node, or extract numeric coordinates. It's also great for validating LLM output - extract a number, check it, route on it. It pairs naturally with the General API Node in this pack: force JSON mode is the clean path, but when the model won't cooperate with structured output, regex is the fallback that still works.

    Honest take: if you're extracting more than two or three fields, you're better off forcing json_object output and using the JSON Parser. Regex extraction is a surgical tool, not a structured-data pipeline. Use it for the one stubborn field, not as your whole parsing strategy.

    Inputs and outputs

    • text (STRING, multiline) - what to search.
    • regex (STRING) - the pattern; default (\d+).
    • group_index (INT) - which capture group; 0–99.
    • all_matches (BOOLEAN) - first match only, or all.
    • delimiter (STRING) - joiner when all_matches is on.
    • text (STRING) - the extracted result.

    Installing

    It's part of the FeiMao-326 pack, so it comes with the other fifteen nodes. ComfyUI Manager (search "Comfyui-General-API-Node") or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/FeiMao-326/Comfyui-General-API-Node.git
    cd Comfyui-General-API-Node
    pip install -r requirements.txt
    

    Restart ComfyUI. Minimal dependencies (openai, numpy, Pillow, requests), no models to fetch.

    CategoryFeiMao-326

    Inputs (5)

    NameTypeDefaultDescription
    textSTRING
    regexSTRING(\d+)
    group_indexINT10–99
    all_matchesBOOLEANfalse
    delimiterSTRING,

    Outputs (1)

    NameTypeDescription
    textSTRING