javascript - Node-Minimatch/Regex: Match subdirectories within a specified subdirectory -
i match subfolders within given subfolder.
let's have following directories:
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
now i'd match in 'rock' , 'pop', restriction of given name. in case it's 'steven'.
the following minimatch glob-rule works fine far:
minimatch('./test', ['!*(rock|pop|steven)'], {matchbase: true}))
translation of rule above:
hide not in rock , pop , steven.
but here's problem: 1 can imagine minimatch doesn't include subdirectories in particular case.
i want like...
minimatch('./test', ['!*(rock|pop|steven|plus_subdirs_of_steven)'], {matchbase: true}))
...but sadly didn't work rule:
minimatch('./test', ['!*(rock|pop|steven/**)'], {matchbase: true}))
my question is: how can hide things except rock+pop+steven+steven's subdirectories ?
a better overview of directory-structure:
test |-rock |--martin |--steven |---coolmusik |----newmusic |-pop |--martin |--steven |---mysubdir |---anothersubdir
also: if there's no way minimatch can handle this, how regular regex rules above like?
you cannot .gitignore-style behavior making list of every file , glob-matching each one. starters, that's ludicrously expensive (you may have .gitignore'd folder 100000 files in or something), , also, have keep track of whether parent ignored. however, gets more complicated, because rule might cause have specific items, if they're un-ignored negated rule.
source: https://github.com/isaacs/minimatch/issues/8#issuecomment-5516685
the owner of 'minimatch' wrote module called fstream-ignore solves problem. however. definately out of scope , not related question. end regular javascript regex, mentioned in original post.
regex:
new regexp(^test\/(rock|pop)(?:\/|$)(?:steven|$)(?:\/.*|$)$);
example:
var re = /^test\/(rock|pop)(?:\/|$)(?:steven|$)(?:\/.*|$)/mg; var paths = 'test/rock/martin\ntest/rock/steven\ntest/rock/steven/coolmusik\ntest/rock/steven/coolmusik/newmusic\ntest/pop/martin\ntest/pop/steven\ntest/pop/steven/mysubdir\ntest/pop/steven/anothersubdir'; var match; while ((match = re.exec(paths)) !== null) { if (match.index === re.lastindex) { re.lastindex++; } var old_content = document.getelementbyid('results').innerhtml; document.getelementbyid('results').innerhtml = old_content + '<br>' + match[0]; }
<b>verify against:</b> <pre> 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 </pre> <br><hr><br> <b>get <u>steven</u>'s results</b>: <div id="results"></div>
Comments
Post a Comment