Match.Groups-Eigenschaft
Ruft eine Auflistung der mit dem regulären Ausdruck übereinstimmenden Gruppen ab.
Namespace: System.Text.RegularExpressions
Assembly: System (in system.dll)
Syntax
'Declaration
Public Overridable ReadOnly Property Groups As GroupCollection
'Usage
Dim instance As Match
Dim value As GroupCollection
value = instance.Groups
public virtual GroupCollection Groups { get; }
public:
virtual property GroupCollection^ Groups {
GroupCollection^ get ();
}
/** @property */
public GroupCollection get_Groups ()
public function get Groups () : GroupCollection
Eigenschaftenwert
Die Zeichengruppen, die mit dem Muster übereinstimmen.
Beispiel
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
string text = "One car red car blue car";
string pat = @"(\w+)\s+(car)";
// Compile the regular expression.
Regex r = new Regex(pat, RegexOptions.IgnoreCase);
// Match the regular expression pattern against a text string.
Match m = r.Match(text);
int matchCount = 0;
while (m.Success)
{
Console.WriteLine("Match"+ (++matchCount));
for (int i = 1; i <= 2; i++)
{
Group g = m.Groups[i];
Console.WriteLine("Group"+i+"='" + g + "'");
CaptureCollection cc = g.Captures;
for (int j = 0; j < cc.Count; j++)
{
Capture c = cc[j];
System.Console.WriteLine("Capture"+j+"='" + c + "', Position="+c.Index);
}
}
m = m.NextMatch();
}
String^ text = "One car red car blue car";
String^ pat = "(\\w+)\\s+(car)";
// Compile the regular expression.
Regex^ r = gcnew Regex( pat,RegexOptions::IgnoreCase );
// Match the regular expression pattern against a text string.
Match^ m = r->Match(text);
int matchCount = 0;
while ( m->Success )
{
Console::WriteLine( "Match{0}", ++matchCount );
for ( int i = 1; i <= 2; i++ )
{
Group^ g = m->Groups[ i ];
Console::WriteLine( "Group{0}='{1}'", i, g );
CaptureCollection^ cc = g->Captures;
for ( int j = 0; j < cc->Count; j++ )
{
Capture^ c = cc[ j ];
System::Console::WriteLine( "Capture{0}='{1}', Position={2}", j, c, c->Index );
}
}
m = m->NextMatch();
}
Plattformen
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0
.NET Compact Framework
Unterstützt in: 2.0, 1.0
Siehe auch
Referenz
Match-Klasse
Match-Member
System.Text.RegularExpressions-Namespace