isaacs / minimatch

a glob matcher in javascript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to match a optional slash?

pycodev opened this issue · comments

I want to match /a or a,

so I test:

console.log(minimatch('/a', '?(/)a'));
console.log(minimatch('a', '?(/)a'));

the results are both false:

false
false

how to write the pattern?

"Extglob" patterns (the kind with parentheses) can only be used for "path parts", ie, the things between the / characters. They cannot contain path separators. (In bash, they are only used to match directory entries.)

To accomplish this, you'll need to use brace expansion: '{/,}a'

Brace expansion happens prior to directory splitting, effectively creating multiple different "patterns" which are positional separate arguments in a bash command invocation.

Hope this clears things up.