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);
                }
            }
相關文章
相關標籤/搜索