Nodes/Vantage-Nodes/Regex Filter (Multiline)
ComfyUI Node

Regex Filter (Multiline)

Filter a multiline list with a regex — keep only the lines that match

By vantagewithai·Created 8 months ago·Updated about a month ago· 25
Regex Filter (Multiline)
    • filtered_text
    • count
    text
    pattern
    invertfalse

    When a prompt list, LLM dump, or tag batch arrives with lines you don't want, this node lets you keep only the ones that match a regex - or, flipped, drop exactly those. It's the "filter this list for me" node, and it's surprisingly useful once you're generating prompt lists programmatically instead of hand-curating them.

    The model here is simple and powerful: every line of your multiline input is tested against the pattern; matching lines survive, the rest are dropped. invert turns that around - non-matching lines survive. You get the filtered text plus a count, so you always know how many lines made the cut.

    What it needs

    • text - the multiline list to filter.
    • pattern - the regex, in Python syntax. Empty pattern means no filtering - the input passes through with its original line count. This is a nice safety property: an empty pattern is "do nothing," not "keep nothing."
    • invert - flip the match. false keeps lines that match; true keeps lines that don't. "Keep everything except lines that contain 'nsfw'", for example.

    Two outputs: filtered_text (the surviving lines, still multiline) and count (how many survived).

    What a real pattern looks like

    Say you have a list of prompts and want only the ones mentioning a character or a style:

    pattern: (?i)cyberpunk
    

    That keeps every line containing "cyberpunk" case-insensitively. To keep lines without a word, tick invert. For a quick sanity check on what matched, the count output is your friend - a zero there means your pattern matched nothing, which is usually a regex bug, not an empty list.

    Two failure behaviors worth knowing: an invalid regex (a pattern that doesn't compile) returns empty text and count 0 instead of crashing, which is safe but confusing; and the match is a search (regex.search), so the pattern doesn't need to anchor the whole line - it just needs to appear somewhere in it. Use ^...$ if you need full-line matching.

    Install

    Part of Vantage-Nodes:

    cd ComfyUI/custom_nodes
    git clone https://github.com/vantagewithai/Vantage-Nodes.git
    pip install -r requirements.txt
    

    or ComfyUI Manager → search "Vantage-Nodes" → Install → restart.

    Common issues

    • Everything got filtered out - your pattern matched nothing. Test it on a single line first; the count output tells you the damage.
    • Regex too loose - red matches "hundred," "cred," anything containing the letters. Anchor or word-bound it (\bred\b) for exact words.
    • Case sensitivity surprises - Python regex is case-sensitive by default; add (?i) at the front or use re.IGNORECASE-style flags in the pattern.
    CategoryVantage/String

    Inputs (3)

    NameTypeDefaultDescription
    textSTRING
    patternSTRING
    invertBOOLEANfalse

    Outputs (2)

    NameTypeDescription
    filtered_textSTRING
    countINT