Search code examples
regexcapturing-groupregex-group

How to use regular express parse file directory hierarchy?


Suppose the file path is "a/b/c/d/e", how can I get a array of 'a', 'b', 'c', 'd', 'e'?
I have consider with this: (?:(.+)/)*?(.+)
but it get empty string,it is really unexpected.


Solution

  • You can try with this one:

    /([^\/]+)/g

    Tested here:

    Regex101