Our system allows both the folder and file could be in regex format. For example
/dir1*/abcd/efg.? is legal.
/dir* could match /dira and also /dirb/cde
I want to find all files that match this pattern. To eliminate unnecessary operation, I want to get the root directory to start the file listing and filtering.
Is there any effective way to get the root directory of a regex path pattern?
Several test cases:
/abc/def*/bc return /abc
/abc/def* return /abc
/ab.c/def* return /
/ab\.c/def* return /ab.c
Edited: Added handling of relative paths
Here’s a test:
Output:
You can fine tune it from there.