This documentation is archived and is not being maintained.

Match.Groups Property

Gets a collection of groups matched by the regular expression.

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

'Declaration
Public Overridable ReadOnly Property Groups As GroupCollection
'Usage
Dim instance As Match
Dim value As GroupCollection

value = instance.Groups

/** @property */
public GroupCollection get_Groups ()

public function get Groups () : GroupCollection

Property Value

The character groups matched by the pattern.

Dim text As String = "One car red car blue car"
Dim pat As String = "(\w+)\s+(car)"
' Compile the regular expression.
Dim r As Regex = new Regex(pat, RegexOptions.IgnoreCase)
' Match the regular expression pattern against a text string.
Dim m As Match = r.Match(text)
Dim matchcount as Integer = 0
While (m.Success)
   matchCount += 1
   Console.WriteLine("Match" & (matchCount))
   Dim i As Integer
   For i = 1 to 2
      Dim g as Group = m.Groups(i)
      Console.WriteLine("Group" & i & "='" & g.ToString() & "'")
      Dim cc As CaptureCollection = g.Captures
      Dim j As Integer 
      For j = 0 to cc.Count - 1
	 Dim c As Capture = cc(j)
         Console.WriteLine("Capture" & j & "='" & c.ToString() _
            & "', Position=" & c.Index)
      Next j
   Next i
   m = m.NextMatch()
End While

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0
Show: