⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ex-10-09

📁 Programming Csharp Source Code(代码) Programming Csharp Source Code
💻
字号:
// Example 10-09: Examining the capture collection

namespace Programming_CSharp
{
   using System;
   using System.Text.RegularExpressions;

   class Test
   {
      public static void Main()
      {
         // the string to parse
         // note that names appear in both 
         // searchable positions
         string string1 = 
            "04:03:27 Jesse 0.0.0.127 Liberty ";
            
         // regular expression which groups company twice
         Regex theReg = new Regex(@"(?<time>(\d|\:)+)\s" +
            @"(?<company>\S+)\s" +
            @"(?<ip>(\d|\.)+)\s" + 
            @"(?<company>\S+)\s");
        
         // get the collection of matches
         MatchCollection theMatches = 
            theReg.Matches(string1);

         // iterate through the collection
         foreach (Match theMatch in theMatches)
         {
            if (theMatch.Length != 0)               
            {
               Console.WriteLine("theMatch: {0}", 
                  theMatch.ToString());          
               Console.WriteLine("time: {0}", 
                  theMatch.Groups["time"]);
               Console.WriteLine("ip: {0}", 
                  theMatch.Groups["ip"]);
               Console.WriteLine("Company: {0}",
                  theMatch.Groups["company"]);

               // iterate over the captures collection 
               // in the company group within the 
               // groups collection in the match
               foreach (Capture cap in 
                  theMatch.Groups["company"].Captures)
               {
                  Console.WriteLine("cap: {0}",cap.ToString());
               }
            }       
         }           
      }               
   }                   
}  

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -