Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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*

like image 466
goryef Avatar asked Apr 18 '26 09:04

goryef


1 Answers

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)
})
like image 62
alexloehr Avatar answered Apr 20 '26 22:04

alexloehr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!