Search code examples
regexpattern-matchingglobnode-glob

Glob matching file or directory


I'm using node-glob, https://github.com/isaacs/node-glob. My structure is:

img/
 -/nested
     image1.png
     image2.jpg
 -/emtpy
 image1.png
 image2.jpg 

I'm trying to get all the images + empty directories

Using

'**/*+(.jpg|.png)'

Results in:

[
    "img/nested/image1.png",
    "img/nested/image2.jpg",
    "img/image1.png",
    "img/image2.png"
]

Using

'**/*/'

Works as expected:

[
    "img/",
    "img/empty/",
    "img/nested/"
]

Trying to combine both results doesn't work at all

'**/*+(.jpg|.png|/)'

Empty array

 []

I would like to have 2 results combined in something like:

[
    "img/",
    "img/empty/",
    "img/nested/"
    "img/nested/image1.png",
    "img/nested/image2.jpg",
    "img/image1.png",
    "img/image2.png",
]

Solution

  • The final solution of our common experimenting session in comments: '**/*{/,+(.jpg|.png)}'