c# 正则

  Regex reg = new Regex("^do(es)(xy)?$");
            var result = reg.Match("doesxy");
            foreach (var item in result.Groups)
            {
                Console.WriteLine(item);
            }
            Match result2 = reg.Match("");
            foreach (var item in result2.Groups)
            {
                Console.WriteLine(item);
            }

            MatchCollection mc = Regex.Matches("1id1sid1x2id2sid2", @"\d*id(\d*)sid(\d*)");
            if (mc[0].Groups.Count == 3)//会有三个匹配项的
            {
                for (int i = 0; i < 3; i++)
                {
                    int x;
                    int.TryParse(mc[0].Groups[i].Value, out x);
                    Console.WriteLine(x);
                }
            }

 

posted @ 2018-01-16 17:13  Danlis  阅读(225)  评论(0编辑  收藏  举报