isaacs / minimatch

a glob matcher in javascript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Negated union doesn't work

emlai opened this issue · comments

Version: 5.1.1
Repro: https://runkit.com/embed/ep80o75pnkl8

Code:

const minimatch = require('minimatch');
const filter = "!(org-a/repo-a|org-b/repo-b)";
const repos = ["org-a/repo-a", "org-b/repo-b", "org-a/repo-b"];
console.log(repos.filter(repo => minimatch(repo, filter)));

Expected output: ["org-a/repo-b"]
Actual output: ["org-a/repo-a", "org-b/repo-b", "org-a/repo-b"]

Extglobs (ie, (...|...) style patterns) cannot contain / characters.

Try this: "!{org-a/repo-a,org-b/repo-b}"

const minimatch = require('minimatch');
const filter = "!["org-a/repo-a", "org-b/repo-b"];

const repos = ["org-a/repo-a", "org-b/repo-b", "org-a/repo-b"];
console.log(repos.filter(repo => minimatch(repo, filter)));

@isaacs Thanks! That worked. But it isn't covered in the docs.

It's covered in the documentation on glob patterns, the best source is typing man bash into almost any terminal. I suppose it could be worthwhile to copy the sections on Pattern Expansion into the readme here, but I'm not sure how many questions it would actually prevent.