Nodes/ComfyUI-String-Function/String Regex Match
ComfyUI Node

String Regex Match

Pull anything out of a string with a pattern

By TakkunRed·Created 5 months ago·Updated 15 days ago· 1
String Regex Match
    • result
    • matched
    • match_count
    ◄text►
    ◄pattern►
    ◄modesearch►
    ◄group0►
    ◄ignore_casefalse►
    ◄multilinefalse►
    ◄join_str, ►

    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 with join_str (default ", "). In findall, the group setting 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 in findall).
    • matched (BOOLEAN) - did anything match? Branch on this.
    • match_count (INT) - how many matches (1 for 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.
    • match is not "search somewhere in the middle." It anchors to the start of the text, like Python's re.match. People coming from "match = find" habit get confused; use search for anywhere-in-the-text.
    • Capturing groups change the result. With a pattern containing groups, group=0 returns the whole match including delimiters; group=1 returns just the first capture. Set group deliberately 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 with join_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.

    CategoryString Function

    Inputs (7)

    NameTypeDefaultDescription
    textSTRING—
    patternSTRING—
    modeCOMBOsearchsearch=どこでも検索, match=先頭から, fullmatch=全体, findall=全件取得
    groupoptINT00–99取得するグループ番号 (0=マッチ全体, 1以降=キャプチャグループ)。findall モードでは無視
    ignore_caseoptBOOLEANfalse—
    multilineoptBOOLEANfalseTrue にすると ^ $ が各行の先頭・末尾にマッチ
    join_stroptSTRING, findall モードで複数結果を結合する区切り文字

    Outputs (3)

    NameTypeDescription
    resultSTRING—
    matchedBOOLEAN—
    match_countINT—