我用正则表达式对文本进行提取,里面有很多个组,我会根据这些组来建立一个DataTable对象,
但现在不知道组名,所以列名的设置就比较麻烦,有什么办法能提取出组名吗?
Group类中没有组名属性.
以下是我用的正则表达式
(?<A日期>\d{4}-[01]?\d-[0-3]?\d)\s+(?:\d{2}:\d{2}:\d{2})\s+(?:限额转帐)\s+(?:\S+)\W+(?:\d+)\W+(?:\w*银行\w*)\W+(?:\d+\.?\d*)\W+(?:\d+\.?\d*)\W+(?<D金额>\d+\.?\d*)\W+(?:\S+)\W+(?<E失败次数>\d+)\W+(?:\S+)\W+(?:\S+)\W+(?:[\d|\W|-]*)\W+(?<F分行>\S*营业部\S*)\W*

解决方案 »

  1.   

    using System;
    using System.Text.RegularExpressions;class MainClass
    {
      public static void Main()
      {
        string text = "(800) 888-1211\n" +
          "(212) 555-1212\n" +
          "(506) 777-1213\n" +
          "(650) 222-1214\n" +
          "(888) 111-1215\n";    string areaCodeRegExp = @"(?<areaCodeGroup>\(\d\d\d\))";    string phoneRegExp = @"(?<phoneGroup>\d\d\d\-\d\d\d\d)";    MatchCollection myMatchCollection = Regex.Matches(text, areaCodeRegExp + " " + phoneRegExp);    foreach (Match myMatch in myMatchCollection)
        {
          Console.WriteLine("Area code = " + myMatch.Groups["areaCodeGroup"]);
          Console.WriteLine("Phone = " + myMatch.Groups["phoneGroup"]);      foreach (Group myGroup in myMatch.Groups)
            foreach (Capture myCapture in myGroup.Captures)
              Console.WriteLine("myCapture.Value = " + myCapture.Value);
        }  }}
      

  2.   

    ■■■■不甘心挣1000、2000的死工资,来这里■■■■免费提供赚钱项目和赚钱教程[www.dmdigo.cn]