π Regex match
Pull text patterns out of strings without opening a script
- matches
- amount
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+againstimg_0042_final.pngβ matches["0042"], amount1. 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
doggives youamount, 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.findallreturns tuples of the captured groups, not the full match. With no groups, you get the full matches. If the shape ofmatchessurprises you, that's Python'sre.findallsemantics doing exactly what you asked. - No match β empty list, amount 0 - not an error. The node never raises on a non-match. Gate on
amountto 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;findallreturns 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'sre.DOTALL, which this node doesn't enable. amountis 0 but text looks right - check the pattern against a regex tester; the node is a faithfulfindall, so the bug is in the pattern, not the plumbing.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| Pattern | STRING | (.+) | β |
| String | STRING | β |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| matches | REGEX_MATCHES | β |
| amount | INT | β |