fast-glob icon indicating copy to clipboard operation
fast-glob copied to clipboard

How to match files under special directory with duplicated multiple level path rule

Open vimcaw opened this issue 3 years ago • 0 comments

Environment

  • OS Version: macOS 11.2.2
  • Node.js Version: 15.6.0

Actual behavior

Can't match the files I want.

Expected behavior

Match target perfectly.

Steps to reproduce

For the following files tree:

.
├── B
│   └── b1
│       └── test.js
├── a
│   ├── A2
│   │   └── a21
│   │       └── other.js
│   └── a1
│       ├── A12
│       │   └── form.js
│       ├── a11
│       │   └── inner.js
│       └── mid.js
├── c
│   └── cc.js
└── index.js

I want to match all files which have a lowercase and numeric name and under a directory of lowercase and numeric name.

The result I want is:

a/a1/mid.js
a/a1/a11/inner.js
c/cc.js
index.js

In a regular expressions, That is very simple by using ^([a-z0-9]\/?)+.js$.

But when I try fg.sync('+(+([a-z0-9])?(/)).js'), that doesn't work, I think it is because Regex groups doesn't support slash mark.

Is any way to do this in fast-glob?

Code sample

fg.sync('+(+([a-z0-9])?(/)).js');

vimcaw avatar Mar 11 '21 01:03 vimcaw