List Filter (NH)
Filter your list by contains, regex, or length
- items
- passed
- rejected
- passed_count
- rejected_count
List Filter (NH) (class NH_ListFilter) is the "keep the items I care about" node for the NH list system. Feed it an NH_LIST from List Create (NH), give it a condition, and it splits the list into passed and rejected, with counts for each. If you've ever tried to filter a list of filenames or prompts inside ComfyUI, you know the options are usually "do it with a custom script node" - this saves you that.
How it works
Each item is checked against your condition string. The condition is written as key:value, and the pack supports a genuine handful of matchers:
contains:foo- substring match, case-insensitive (also the fallback if you type a bare word).startswith:foo/endswith:foo- prefix/suffix.regex:pattern- full regular expression search.equals:foo- case-insensitive exact match.len>5,len<=10,len==4- compare item length with any of>,<,>=,<=,==,!=.
mode decides what happens to matches: include keeps them in passed, exclude does the opposite (useful for "drop everything containing 'test'"). Both halves are returned as NH_LISTs, plus passed_count and rejected_count, so you can see what survived without counting by hand.
Where you'd actually use it
Pair it with List Create (NH) to whittle down a set of filenames or tags before feeding a downstream selector. A classic: load a folder of images, build a list of names, filter out the ones matching contains:_preview, and route the survivors onward. It also composes - you can chain two filters to apply contains: and len> in sequence, since there's no "and" in a single condition.
Installing
ComfyUI Manager → search NH-Nodes → install → restart. Or:
cd ComfyUI/custom_nodes
git clone https://github.com/jetthuangai/NH-Nodes.git
cd NH-Nodes
pip install -r requirements.txt
Restart and refresh the browser tab. No extra dependencies for this one.
Gotchas
The default condition is contains:dress - a leftover from the author's garment-workflow examples, so change it or you'll wonder why only items with "dress" in them survive. Case sensitivity varies by matcher: contains and equals lower-case both sides, but startswith/endswith/regex are case-sensitive as written. And a malformed condition doesn't error loudly - it degrades to a plain contains check, which can silently return everything. If your filter looks like it's doing nothing, re-read your condition string.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| items | NH_LIST | — | |
| condition | STRING | contains:dress | — |
| mode | COMBO | 2 options: include, exclude |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| passed | NH_LIST | — |
| rejected | NH_LIST | — |
| passed_count | INT | — |
| rejected_count | INT | — |