node.jswildcardglob

How to glob multiple patterns in Node.js?


Is it possible to include multiple patterns in a single search string in glob for Node.js?

For example to find all files named *abc*.pdf and *xyz.pdf*


Solution

  • When using node-glob you can provide multiple patterns like this:

    "*(pattern1|pattern2|...)"
    

    Which would translate in your example like:

    "*(abc.pdf|xyz.pdf)"
    

    Full example to find all .html and .js files in the current directory:

    glob("*(*.js|*.html)", {}, function (err, files) {
       console.log(files)
    })