topics/cate_34/taicha/bdcs/cate_12/abc/cate_13/taicha/baidu
以cate_\d+为分隔,我想取最后一个直到结束,应该怎么做?谢谢.
有以下几种分组方式:
1.cate_34/taicha/bdcs/cate_12/abc/cate_13/taicha/baidu
2.cate_12/abc/cate_13/taicha/baidu
3.cate_13/taicha/baidu
我只想要最后一组,应该怎么做?谢谢.
我这样写,只能取到第一种,怎么办?谢谢.
(?:Cate[._-])(?<PathCateID>[^/\s.]+)/(?<Path>(?!Cate[._-]*).*)/?

解决方案 »

  1.   

    /?(cate_(?<v>\d+))/?(?<x>[^\d]+)$
      

  2.   

    这样就可以了,
    cate_\d+[^\d]+$
      

  3.   

    /?(cate_\d+(?:(?!cate_\d+).)+$)
    这样更好,可以匹配后面有数字的串,
      

  4.   

                List<string> list = new List<string> { "cate_34/taicha/bdcs/cate_12/abc/cate_13/taicha/baidu", "cate_12/abc/cate_13/taicha/baidu", "cate_13/taicha/baidu" };
                Regex reg = new Regex(@"(?i)cate_\d+(?:(?!cate_\d+).)*$");
                foreach (string s in list)
                    Console.WriteLine(reg.Match(s).Value);