Nodes/FlowNodes/πŸ” Regex match
ComfyUI Node

πŸ” Regex match

Pull text patterns out of strings without opening a script

By gitmyloΒ·Created 2 years agoΒ·Updated about a year agoΒ· 13
πŸ” Regex match
    • matches
    • amount
    β—„Pattern(.+)β–Ί
    β—„Stringβ–Ί

    Some workflows live on text: prompt lists, filenames, CSV rows, metadata. The "πŸ” Regex match" node is FlowNodes' way of pulling structured data out of a string with a regex pattern - no Execute Python node required. You give it a pattern and some text, and it hands you every match plus a count.

    The mechanism is one line of Python: re.findall(Pattern, String, re.MULTILINE). It runs the pattern against the string in multiline mode and returns a list of matches. Two outputs: matches (a list of whatever the pattern captured) and amount (an INT - len(matches)).

    The inputs

    • Pattern - the regex. Default (.+), which matches one-or-more of anything per line. This is a single-line box, so keep the pattern compact.
    • String - the text to search, and this one is a multiline box, so paste your whole block in.

    The difference matters: pattern stays one line, text can be many. If your pattern contains a \n-spanning group, remember it's running with re.MULTILINE.

    What you'd actually do with it

    • Extract numbers from a filename: pattern \d+ against img_0042_final.png β†’ matches ["0042"], amount 1. Feed the int to a seed or a counter.
    • Split a prompt list into lines: pattern (.+) with multiline turns each line into a match - which, wired through the batch/list converters, becomes separate items.
    • Pull tags or keys out of metadata or CSV rows and feed them to a Generic operation or a script.
    • Count occurrences: pattern dog gives you amount, ready to gate a branch with an If condition.

    Where regex shines is validation-and-route: check that a string contains the thing you expect (amount > 0), then decide. That's a Compare node feeding an If condition - a whole conditional, no Python.

    The gotchas

    • The output is a list of matches. With a pattern containing capture groups (...), re.findall returns tuples of the captured groups, not the full match. With no groups, you get the full matches. If the shape of matches surprises you, that's Python's re.findall semantics doing exactly what you asked.
    • No match β†’ empty list, amount 0 - not an error. The node never raises on a non-match. Gate on amount to detect "not found."
    • Regex is a language - if you're new to it, \d+, (.+), ^...$, and | cover 90% of real needs. For anything exotic, test the pattern in a scratch Python file before putting it in the node.

    Install

    Part of the FlowNodes pack:

    cd ComfyUI/custom_nodes
    git clone https://github.com/gitmylo/FlowNodes
    # restart ComfyUI
    

    or ComfyUI Manager β†’ search FlowNodes β†’ install. No Python dependencies, no models - regex is in the standard library.

    Troubleshooting

    • Match list looks wrong with groups - you added (...) capture groups; findall returns the groups. Remove the parentheses or wrap the whole pattern.
    • Multiline text doesn't match as expected - the node uses re.MULTILINE, so ^ and $ match at line boundaries. If you wanted . to also match newlines, that's re.DOTALL, which this node doesn't enable.
    • amount is 0 but text looks right - check the pattern against a regex tester; the node is a faithful findall, so the bug is in the pattern, not the plumbing.
    CategoryπŸ”‚ FlowNodes/function

    Inputs (2)

    NameTypeDefaultDescription
    PatternSTRING(.+)β€”
    StringSTRINGβ€”

    Outputs (2)

    NameTypeDescription
    matchesREGEX_MATCHESβ€”
    amountINTβ€”