C#正则表达式GroupCollection类浅析

开发 后端
C#正则表达式GroupCollection类是什么含义呢?C#正则表达式GroupCollection类是如何使用的呢?那么本问就向你简单介绍C#正则表达式GroupCollection类的具体内容。

C#正则表达式GroupCollection类是什么呢?C#正则表达式GroupCollection类是如何使用的呢?下面让我们来具体的内容:

下面通过介绍 .NET 框架的正则表达式类,熟悉一下.NET框架下的正则表达式的使用方法。

C#正则表达式GroupCollection类表示捕获的组的集合

该集合为只读的,并且没有公共构造函数。GroupCollection 的实例在 Match.Groups 属性返回的集合中返回。下面的控制台应用程序查找并输出由正则表达式捕获的组的数目。

C#正则表达式GroupCollection类实例应用:

  1. using System;  
  2.  
  3. using System.Text.RegularExpressions;  
  4.  
  5. public class RegexTest   
  6.  
  7. {  
  8.  
  9.  public static void RunTest()   
  10.  
  11.  {  
  12.  
  13. Regex r = new Regex("(a(b))c");   
  14.  
  15. //定义组  
  16.  
  17. Match m = r.Match("abdabc");  
  18.  
  19. Console.WriteLine(  
  20. "Number of groups found = " + m.Groups.Count);  
  21.  
  22.  }  
  23.  
  24.  public static void Main()   
  25.  
  26.  {  
  27.  
  28.   RunTest();  
  29.  
  30.  }  
  31.  
  32. }   

该示例产生下面的输出:

  1. Number of groups found = 3  

C#正则表达式GroupCollection类的基本内容就向你介绍到这里,希望对你了解和学习C#正则表达式GroupCollection类有所帮助。

【编辑推荐】

  1. C#正则表达式之对[0,100]的匹配
  2. C#正则表达式字符串搜索浅析
  3. C#正则表达式Regex类浅析
  4. C#正则表达式Match类浅析
  5. C#正则表达式MatchCollection类浅析
责任编辑:仲衡 来源: 百度空间
相关推荐

2009-08-20 15:10:33

C#正则表达式

2009-08-20 14:57:00

C#正则表达式

2009-08-20 15:02:41

C#正则表达式

2009-08-20 14:43:03

C#正则表达式Rege

2009-08-07 15:16:10

C#正则表达式

2009-08-20 13:09:28

C#正则表达式

2009-08-20 13:57:27

C#正则表达式

2009-08-20 13:26:35

C#正则表达式

2009-08-17 13:56:28

C#正则表达式入门

2009-08-03 17:27:14

C#正则表达式

2009-08-20 16:13:32

C#正则表达式匹配

2009-08-20 14:31:55

C#正则表达式字符串

2009-08-20 13:30:38

C#正则表达式

2009-08-20 16:02:15

C#正则表达式

2009-09-16 17:15:57

正则表达式引擎

2009-08-11 13:00:41

C#正则表达式

2009-08-13 15:24:27

C#正则表达式

2009-08-20 13:48:37

C#正则表达式

2009-08-20 13:38:58

C#正则表达式

2009-08-20 13:23:00

C#正则表达式
点赞
收藏

51CTO技术栈公众号