12sss

GroupCollection Class

Returns the set of captured groups in a single match.

Namespace:  System.Text.RegularExpressions
Assembly:  System (in System.dll)

 

Syntax

 

 


 

 

System.Object
  System.Text.RegularExpressions.GroupCollection


 

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

 

Remarks

The collection is immutable (read-only) and has no public constructor. A GroupCollection object is returned by the Match.Groups property.

The collection contains one or more System.Text.RegularExpressions.Group objects. If the match is successful, the first element in the collection contains the Group object that corresponds to the entire match. Each subsequent element represents a captured group, if the regular expression includes capturing groups. If the match is unsuccessful, the collection contains a single System.Text.RegularExpressions.Group object whose Success property is falseand whose Value property equals String.Empty.

To iterate through the members of the collection, you should use the collection iteration construct provided by your language (such as foreach in C# and For EachNext in Visual Basic) instead of retrieving the enumerator that is returned by the GetEnumerator method.


 

The following example uses a regular expression with capturing groups to extract information about trademarks and registered trademarks used in text. The regular expression pattern is /b(/w+?)([/u00AE/u2122]), which is interpreted as shown in the following table.

 

For each match, the GroupCollection contains three Group objects. The first object contains the string that matches the entire regular expression. The second object, which represents the first captured group, contains the product name. The third object, which represents the second captured group, contains the trademark or registered trademark symbol.

 

The example displays the following output:

Pattern

Description

/b

Look for a word boundary.

(/w+?)

Look for one or more word characters. Together, these form the trademarked name. (Note that this regular expression assumes that a trademark consists of a single word.) This is the first capturing group.

([/u00AE/u2122])

Look for either the ® or the ™ character. This is the second capturing group.

Examples

Thread Safety

Inheritance Hierarchy

 

 

 

 

 

 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值