using System;
using System.Text.RegularExpressions;
namespace P10_17
{
    class Program
    {
        static void Main(string[] args)
        {
            string text = "One car red car";
            string pat = @"(\w+)\s+(car)";
            // ʽʵ
            Regex r = new Regex(pat, RegexOptions.IgnoreCase);
            // һıַʹʽƥ
            Match m = r.Match(text);
            int matchCount = 0;
            while (m.Success)
            {
                Console.WriteLine("Match" + (++matchCount));
                for (int i = 1; i <= 2; i++)
                {
                    Group g = m.Groups[i];
                    Console.WriteLine("Group" + i + "='" + g + "'");
                    CaptureCollection cc = g.Captures;
                    for (int j = 0; j < cc.Count; j++)
                    {
                        Capture c = cc[j];
                        System.Console.WriteLine("Capture" + j + "='" + c + "', Position=" + c.Index);
                    }
                }
                m = m.NextMatch();
            }
            Console.ReadLine();
        }
    }
}
