本文整理汇总了VB.NET中System.Text.RegularExpressions.GroupCollection.Item属性的典型用法代码示例。如果您正苦于以下问题:VB.NET GroupCollection.Item属性的具体用法?VB.NET GroupCollection.Item怎么用?VB.NET GroupCollection.Item使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.Text.RegularExpressions.GroupCollection
的用法示例。
在下文中一共展示了GroupCollection.Item属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: Example
' 导入命名空间
Imports System.Text.RegularExpressions
Module Example
Public Sub Main()
Dim pattern As String = "(\d+)*(\w)\2"
Dim input As String = "AA"
Dim match As Match = Regex.Match(input, pattern)
' Get the first named group.
Dim group1 As Group = match.Groups.Item(1)
Console.WriteLine("Group 1 value: {0}", If(group1.Success, group1.Value, "Empty"))
' Get the second named group.
Dim group2 As Group = match.Groups.Item(2)
Console.WriteLine("Group 2 value: {0}", If(group2.Success, group2.Value, "Empty"))
' Get a non-existent group.
Dim group3 As Group = match.Groups.Item(3)
Console.WriteLine("Group 3 value: {0}", If(group3.Success, group3.Value, "Empty"))
End Sub
End Module
输出:
Group 1 value: Empty Group 2 value: A Group 3 value: Empty
示例2: Example
' 导入命名空间
Imports System.Text.RegularExpressions
Module Example
Public Sub Main()
Dim pattern As String = "(?<numbers>\d+)*(?<letter>\w)\k<letter>"
Dim input As String = "AA"
Dim match As Match = Regex.Match(input, pattern)
' Get the first named group.
Dim group1 As Group = match.Groups.Item("numbers")
Console.WriteLine("Group 'numbers' value: {0}", If(group1.Success, group1.Value, "Empty"))
' Get the second named group.
Dim group2 As Group = match.Groups.Item("letter")
Console.WriteLine("Group 'letter' value: {0}", If(group2.Success, group2.Value, "Empty"))
' Get a non-existent group.
Dim group3 As Group = match.Groups.Item("none")
Console.WriteLine("Group 'none' value: {0}", If(group3.Success, group3.Value, "Empty"))
End Sub
End Module
输出:
Group 'numbers' value: Empty Group 'letter' value: A Group 'none' value: Empty