本文整理匯總了VB.NET中System.Text.RegularExpressions.Regex.GetGroupNames方法的典型用法代碼示例。如果您正苦於以下問題:VB.NET Regex.GetGroupNames方法的具體用法?VB.NET Regex.GetGroupNames怎麽用?VB.NET Regex.GetGroupNames使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Text.RegularExpressions.Regex
的用法示例。
在下文中一共展示了Regex.GetGroupNames方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: Example
' 導入命名空間
Imports System.Text.RegularExpressions
Module Example
Public Sub Main()
Dim pattern As String = "\b(?<FirstWord>\w+)\s?((\w+)\s)*(?<LastWord>\w+)?(?<Punctuation>\p{Po})"
Dim input As String = "The cow jumped over the moon."
Dim rgx As New Regex(pattern)
Dim match As Match = rgx.Match(input)
If match.Success Then ShowMatches(rgx, match)
End Sub
Private Sub ShowMatches(r As Regex, m As Match)
Dim names() As String = r.GetGroupNames()
Console.WriteLine("Named Groups:")
For Each name In names
Dim grp As Group = m.Groups.Item(name)
Console.WriteLine(" {0}: '{1}'", name, grp.Value)
Next
End Sub
End Module
輸出:
Named Groups: 0: 'The cow jumped over the moon.' 1: 'the ' 2: 'the' FirstWord: 'The' LastWord: 'moon' Punctuation: '.'