System.Text.RegularExpressions.MatchCollection Class

Represents the set of successful matches found by iteratively applying a regular expression pattern to the input string.

See Also: MatchCollection Members


public class MatchCollection : ICollection


The collection is immutable (read-only) and has no public constructor. The Regex.Matches(string, string) method returns a System.Text.RegularExpressions.MatchCollection object.

The collection contains zero or more System.Text.RegularExpressions.Match objects. If the match is successful, the collection is populated with one System.Text.RegularExpressions.Match object for each match found in the input string. If the match is unsuccessful, the collection contains no System.Text.RegularExpressions.Match objects, and its MatchCollection.Count property equals zero.

When applying a regular expression pattern to a particular input string, the regular expression engine uses either of two techniques to build the System.Text.RegularExpressions.MatchCollection object:

To iterate through the members of the collection, you should use the collection iteration construct provided by your language (such as foreach in C# and For Each…Next in Visual Basic) instead of retrieving the enumerator that is returned by the MatchCollection.GetEnumerator method.


Namespace: System.Text.RegularExpressions
Assembly: System (in System.dll)
Assembly Versions: 1.0.3300.0, 1.0.5000.0,,