【发布时间】:2015-07-05 19:14:43
【问题描述】:
我想匹配给定子文件夹中的所有子文件夹。
假设我有以下目录:
test/rock/martin
test/rock/steven
test/rock/steven/coolmusik
test/rock/steven/coolmusik/newmusic
test/pop/martin
test/pop/steven
test/pop/steven/mysubdir
test/pop/steven/anothersubdir
现在我想匹配 'rock' 和 'pop' 中的所有内容,但有给定名称的限制。在这种情况下,它是“史蒂文”。
到目前为止,以下minimatch glob-rule 工作正常:
minimatch('./test', ['!*(rock|pop|steven)'], {matchBase: true}))
上述规则的翻译:
隐藏所有不在摇滚、流行和史蒂文中的东西。
但是问题来了: 可以想象 minimatch 在这种特殊情况下不包括子目录。
我希望它像...
minimatch('./test', ['!*(rock|pop|steven|PLUS_SUBDIRS_OF_STEVEN)'], {matchBase: true}))
...但遗憾的是它不符合我的规则:
minimatch('./test', ['!*(rock|pop|steven/**)'], {matchBase: true}))
我的问题是: 除了rock+pop+steven+steven的子目录之外,我怎样才能隐藏所有的东西?
更好地了解目录结构:
test
|-rock
|--martin
|--steven
|---coolmusik
|----newmusic
|-pop
|--martin
|--steven
|---mysubdir
|---anothersubdir
另外:如果 minimatch 无法处理这个问题,上面规则的常规正则表达式会是什么样子?
【问题讨论】:
-
你试过
minimatch('./test/**'吗?它是你的noglobstar未标记? -
是的,但是没有用。它不会与路径匹配。
标签: javascript regex node.js regex-negation minimatch