日期:2014-05-17  浏览次数:20487 次

*****高分求正则******
求一正则,要求实现:
如果url是:www.bj.com/p1a33c33d2f4g9h11m2/
通过正则能提取出: p1、a33、c33、d2、f4、g9、h11、m2

如果url是:www.bj.com/p1a33c33d2f4g9h11m2/?type=bb&fac=2&d=3
通过正则能提取也:p1、a33、c33、d2、f4、g9、h11、m2、type=bb、fac=2、d=3

需要注意:p1a33c33d2f4g9h11m2,字母占位符顺序不是固定的,也有可能
          a33c33p1d2f4h11g9m2

------解决方案--------------------
 static void Main(string[] args)
        {
            Func<string, string[]> getvalues = (text) =>
                {
                    string[] txts = text.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
                    List<string> list = new List<string>();
                    MatchCollection mc = Regex.Matches(txts[1], "[a-z][0-9]+");
                    string[] res = new string[mc.Count];
                    for (int i = 0; i < mc.Count; i++)
                    {
                        list.Add(mc[i].Groups[0].Value);
                    }
                    if (txts.Length > 2)
                    {
                        if (txts[2].Contains('&'))
                        {
                            txts[2] = txts[2].Contains('?') ? txts[2].Replace("?", "") : txts[2];
                            txts[2].Split('&').ToList().ForEach(x => list.Add(x));
                        }
                        else