Parsing valid parent directories with regex

后端 未结 3 1464
感情败类
感情败类 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:23

    Completely different answer without reversing string.

    (?<=((?:\w+(?:/|$))+(?=\w)))
    

    This matches

    a/
    a/b/
    a/b/c/
    

    but you have to use C# which use variable lookbehind

提交回复
热议问题