Parsing valid parent directories with regex

后端 未结 3 1459
感情败类
感情败类 2021-01-29 09:58

Given the string a/b/c/d which represents a fully-qualified sub-directory I would like to generate a series of strings for each step up the parent tree, i.e.

3条回答
  •  一整个雨季
    2021-01-29 10:28

    Yes, it's possible:

    /([^\/]*)\//
    

    So basically it replaces your .*? with [^/]*, and it does not have to be non-greedy. Since / is a special character in your case, you will have to escape it, like so: [^\/]*.

提交回复
热议问题