Wednesday, June 5, 2024
 Popular · Latest · Hot · Upcoming
166
rated 0 times [  169] [ 3]  / answers: 1 / hits: 18690  / 10 Years ago, sat, june 14, 2014, 12:00:00

I just found http://gruntjs.com/configuring-tasks#globbing-patterns, which is the most helpful reference I've found.



I keep seeing:




For more on glob pattern syntax, see the node-glob and minimatch documentation.




Yet, I can't seem to find an exhaustive list of the syntax/usage. These tests might be the best reference, yet still not particularly easy to decipher.



It seems I must be missing some critical source of documentation.



I'm wondering the differences between:



path
path/
path/*
path/*.*
path/**
path/**/
path/**/*
path/**/*.*


and any other important variations that are related that I might have omitted. I'm guessing this applies differently when doing a node-glob style matching ('public/**/*.*') and a .gitignore (node_modules), because in the former, you need to explicitly include everything, many layers deep, and in gitignore, this is handled automatically by ignoring any directory. Is this correct?


More From » node.js

 Answers
93

First of all, I have never worked with node-glob or minimatch libraries. But probably I can still help. There's kind of known syntax for glob pattern matching, but frankly, a quick search in Google shows nothing short and clear. Probably this - http://hgbook.red-bean.com/read/file-names-and-pattern-matching.html#id381184 - is the best resource I've found. The article in Wikipedia is exhaustive and not readable - http://en.wikipedia.org/wiki/Glob_(programming).



In short, IMHO for node-glob:




  • * - stands for any number of characters for a filename, but can't stand for /

  • ** - same as * but crosses folder boundaries

  • [abxy] - can replace any one character from a list; [0-9] can stand for any number



Hence to your example:




  • path/* - all files and folders in path not recoursive

  • path/** - everything in path recoursively

  • path/*.* - all files and folders with point in name; matches a.txt, .hidden, noextension., folder.out, ...



From minimatch documentation - https://github.com/isaacs/minimatch, - it does the same, but utilizes richer and slightly more difficult syntax of Regular Expressions. You may look here for a comprehesive reference - http://www.w3schools.com/js/js_regexp.asp. In short, path/.* stands for anything below the path, but it's not clear if recursive or not. You may probably test it.


[#70573] Thursday, June 12, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
rhiannab

Total Points: 370
Total Questions: 98
Total Answers: 100

Location: Samoa
Member since Mon, Nov 8, 2021
3 Years ago
;