Nodes/comfyui-wwdm-aicd/Text Filter Lines
ComfyUI Node

Text Filter Lines

Keep the lines that match

By wwsmiao·Created 4 months ago·Updated 4 months ago· 0
Text Filter Lines
    • lines
    text
    pattern
    modegrep
    matchcontains
    ignore_casefalse
    trim_linestrue

    If you've ever piped text through grep on the command line, you already know what TextFilterLines does - it's grep as a ComfyUI node. Feed it a multi-line blob of text, give it a pattern, and it returns the lines that match (or, with grep_v, the lines that don't). It's the README's chosen middle step in the LLM pipeline - AIChatAPI output → TextFilterLines → TextSplit → JsonParser - and it earns that spot, because LLM output is exactly the kind of noisy multi-line text you want to filter by keyword.

    The inputs that matter: text (the multi-line string), pattern (what to match), mode (grep keeps matches, grep_v drops them), and match (how to match). match has five flavors: contains, regex, starts, ends, and equals. contains is the default and covers most cases - keep every line that mentions "error", or drop every line that mentions "DEBUG". regex is the power option: pattern: "\\d+" keeps only lines containing digits. starts/ends/equals are for when you want line-anchored matching. Two optional toggles round it out: ignore_case, and trim_lines, which is on by default and strips leading/trailing whitespace from each line before matching (and drops empty lines). That default is a small gift - it means a line with trailing spaces won't silently fail a ends match.

    Mechanically it's straightforward: split on newlines, optionally trim, then test each line against the pattern with whichever match type you picked, collecting into a STRING list output. Regex errors are tolerated - a bad pattern simply matches nothing - which is friendly but means a typo gives you an empty result, not an error. If your grep_v output looks wrong, check the pattern first.

    The workflow shape it unlocks: LLM returns a long response, you keep only the lines that look like structured data, then feed those into TextSplit or TxtReg. Or filter a log for error lines before passing them to AIChatAPI for summarization. Or the classic - keep the "positive" entries and drop the "negative" ones from a batch result.

    Install is the pack standard:

    cd ComfyUI/custom_nodes
    git clone https://github.com/wwsmiao/comfyui-wwdm-aicd.git
    

    Restart ComfyUI, look under wwdm-aicd. Pure stdlib plus re, no dependencies, no requirements.txt in the repo despite what the README's install block suggests - clone and restart is all it needs. The README and source comments are in Chinese; the widgets are English.

    Two quirks to remember. trim_lines is on by default, so if you need to match leading whitespace (indentation-sensitive content), flip it off. And the output is always a list - if you want a single joined string, you'll route it through ListOps join afterward. It's a small node with a narrow job, but it's one of the genuinely useful ones in the pack because it turns "here's a wall of text" into "here are the lines that matter."

    Categorywwdm-aicd

    Inputs (6)

    NameTypeDefaultDescription
    textSTRING
    patternSTRING
    modeCOMBOgrep2 options: grep, grep_v
    matchCOMBOcontains5 options: contains, regex, starts, ends, equals
    ignore_caseoptBOOLEANfalse
    trim_linesoptBOOLEANtrue

    Outputs (1)

    NameTypeDescription
    linesSTRING