Nodes/ComfyUI-Apt_Preset/IO_RegexPreset
ComfyUI Node

IO_RegexPreset

Build a working regex from plain language, not trial and error

By cardenluo·Created 2 years ago·Updated 22 days ago· 309
IO_RegexPreset
    • regex_pattern
    • rule_description
    preset自定义
    custom_regex
    keyword
    ignore_casetrue
    escape_special_charstrue
    preview_test_text

    Nobody wants to debug a regular expression against real filenames one Ctrl+F at a time. IO_RegexPreset is this pack's fix for that: pick a plain-language preset - "contains keyword," "starts with keyword," "matches digits" - and it hands you back a working regex_pattern string, ready to plug into anything else in the pack (or elsewhere) that takes a regex.

    How it works

    The preset dropdown carries around nineteen options in plain language rather than regex syntax: excluding empty content, excluding empty-plus-whitespace, containing a keyword, not containing a keyword, starting or ending with a keyword, multi-keyword OR/AND matching, batch-excluding several keywords, and pattern classes like "matches digits," "matches letters," and "matches Chinese characters," among others. Pick one, fill in keyword if the preset needs it (or custom_regex if you're writing your own and just want the extras this node adds), and toggle ignore_case and escape_special_chars as needed - the latter is on by default, which matters if your keyword itself contains regex metacharacters like . or ( that you want treated literally rather than as regex syntax. preview_test_text lets you paste a sample string right into the node and see whether your pattern actually matches before wiring it anywhere.

    Inputs and outputs

    • preset - the plain-language rule to build (defaults to a custom/自定义 option if you'd rather write your own).
    • keyword - the term the preset operates on, where relevant.
    • custom_regex - your own pattern, if you're not using a preset.
    • ignore_case, escape_special_chars - matching behavior toggles, both default true.
    • preview_test_text - paste sample text here to sanity-check the pattern live.

    Two outputs, both STRING: regex_pattern, the actual pattern to feed downstream, and rule_description, a human-readable summary of what it does - useful if you're documenting a workflow for someone else, or for your future self six months from now.

    How to install it

    ComfyUI Manager → search ComfyUI-Apt_Preset, install, restart. Manually:

    cd ComfyUI/custom_nodes
    git clone https://github.com/cardenluo/ComfyUI-Apt_Preset.git
    

    then run install.bat for dependencies (Windows-only - on Linux/macOS run its pip install lines by hand) and restart ComfyUI.

    Common issues & troubleshooting

    This node exists to feed other nodes, not to stand alone. Its own output is just two strings - the payoff is wiring regex_pattern into something that actually filters or sorts, like this pack's IO_PathProcessor (regex_filter / regex_sort_pattern), both of which take a plain STRING and are directly wire-compatible.

    A keyword with regex-special characters behaves oddly with escape_special_chars off. If your keyword is something like file(1) and you turn off escaping, the parentheses get read as regex grouping syntax instead of literal characters - leave escaping on unless you specifically need raw regex syntax in the keyword field.

    IMPORT FAILED on startup. This pack has at least one reported import failure in the wild on a stock install, usually down to skipping install.bat's dependency step - which won't run automatically off Windows. Check the console log for the actual missing package before reinstalling from scratch.

    CategoryApt_Preset/IO_Port

    Inputs (6)

    NameTypeDefaultDescription
    presetCOMBO自定义19 options: 排除空内容, 排除空+纯空白, 包含关键词, 不包含关键词, 以关键词开头, 以关键词结尾, +13
    custom_regexoptSTRING
    keywordoptSTRING
    ignore_caseoptBOOLEANtrue
    escape_special_charsoptBOOLEANtrue
    preview_test_textoptSTRING

    Outputs (2)

    NameTypeDescription
    regex_patternSTRING
    rule_descriptionSTRING