本文整理匯總了VB.NET中System.Text.RegularExpressions.Regex.GetGroupNumbers方法的典型用法代碼示例。如果您正苦於以下問題:VB.NET Regex.GetGroupNumbers方法的具體用法?VB.NET Regex.GetGroupNumbers怎麽用?VB.NET Regex.GetGroupNumbers使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Text.RegularExpressions.Regex
的用法示例。
在下文中一共展示了Regex.GetGroupNumbers方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: Example
' 導入命名空間
Imports System.Text.RegularExpressions
Module Example
Public Sub Main()
Dim pattern As String= "\b((?<word>\w+)\s*)+(?<end>[.?!])"
Dim input As String = "This is a sentence. This is a second sentence."
Dim rgx As New Regex(pattern)
Dim groupNumbers() As Integer = rgx.GetGroupNumbers()
Dim m As Match = rgx.Match(input)
If m.Success Then
Console.WriteLine("Match: {0}", m.Value)
For Each groupNumber In groupNumbers
Dim name As String = rgx.GroupNameFromNumber(groupNumber)
Dim number As Integer
Console.WriteLine(" Group {0}{1}: '{2}'",
groupNumber,
If(Not String.IsNullOrEmpty(name) And
Not Int32.TryParse(name, number),
" (" + name + ")", String.Empty),
m.Groups(groupNumber).Value)
Next
End If
End Sub
End Module
輸出:
Match: This is a sentence. Group 0: 'This is a sentence.' Group 1: 'sentence' Group 2 (word): 'sentence' Group 3 (end): '.'