String Regex Match
Pull anything out of a string with a pattern
- result
- matched
- match_count
String Regex Match is the power tool of the TakkunRed ComfyUI-String-Function pack. Where the slicing nodes and String Find work on fixed positions, this one matches patterns - and patterns are how you pull a version number out of v2.1.4-beta, grab every digit from a caption, or extract the month from a 2026-08-27 date without caring about the exact layout. If you've ever wished a string node could do a "find and capture," this is it.
It's also the escape hatch for the pack's position-based nodes. Fixed slicing breaks the moment text shifts by a character; regex holds on to a structure no matter where it sits. In a workflow full of parsed filenames, LLM output and generated text, that's the difference between a graph that survives format drift and one that silently breaks.
How it works
It's a thin, careful wrapper over Python's re module with four modes:
search(default) - find the pattern anywhere in the text.match- match from the start of the text.fullmatch- the entire text must match the pattern.findall- return every match, joined into one string withjoin_str(default", "). Infindall, thegroupsetting is ignored and matches are collected wholesale.
The group input (default 0) picks which capture group to return - 0 is the whole match, 1+ is a parenthesised group, handy for (\d{4})-(\d{2})-(\d{2}) style parsing where you want just the month. ignore_case and multiline (makes ^/$ match line starts/ends) round out the flags.
Two design details worth calling out. First, an invalid pattern doesn't crash the graph - it returns a string like [regex error: ...], matched=False, match_count=0, so a typo is diagnosable instead of fatal. Second, the three-way output (result, matched, match_count) lets downstream logic branch on whether anything matched at all, which is exactly what a parsing pipeline needs.
Inputs and outputs
Required: text, pattern, mode. Optional: group, ignore_case, multiline, join_str. Outputs:
result(STRING) - the extracted match (or joined matches infindall).matched(BOOLEAN) - did anything match? Branch on this.match_count(INT) - how many matches (1for search/match/fullmatch).
Installing it
Same pack, same zero-dependency story:
cd ComfyUI/custom_nodes
git clone https://github.com/TakkunRed/ComfyUI-String-Function
Or search "ComfyUI-String-Function" in ComfyUI Manager, restart, and grab it under String Function.
Where people get burned
- Regex is a different language, and it's case- and whitespace-sensitive.
\d+finds digits;\d+(with a trailing space) finds digits followed by a space - subtle differences that change results. Test patterns in a scratch tool before wiring them into a workflow. matchis not "search somewhere in the middle." It anchors to the start of the text, like Python'sre.match. People coming from "match = find" habit get confused; usesearchfor anywhere-in-the-text.- Capturing groups change the result. With a pattern containing groups,
group=0returns the whole match including delimiters;group=1returns just the first capture. Setgroupdeliberately or you'll get more text than you bargained for. - In
findall, a pattern with groups returns tuples, and the node joins each tuple's pieces withjoin_str. A(\d+)-(\d+)pattern in findall mode gives you the two numbers joined per match, then all matches joined - read the outputs before trusting them.
When the layout is stable, String Find + String Mid is simpler. When it isn't, this is the node that keeps your workflow alive across format drift.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| text | STRING | — | |
| pattern | STRING | — | |
| mode | COMBO | search | search=どこでも検索, match=先頭から, fullmatch=全体, findall=全件取得 |
| groupopt | INT | 00–99 | 取得するグループ番号 (0=マッチ全体, 1以降=キャプチャグループ)。findall モードでは無視 |
| ignore_caseopt | BOOLEAN | false | — |
| multilineopt | BOOLEAN | false | True にすると ^ $ が各行の先頭・末尾にマッチ |
| join_stropt | STRING | , | findall モードで複数結果を結合する区切り文字 |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| result | STRING | — |
| matched | BOOLEAN | — |
| match_count | INT | — |