System.Text.RegularExpressions.Regex.Matches Method

Searches the specified input string for all occurrences of a specified regular expression, using the specified matching options and time-out interval.

Syntax

[System.MonoTODO("Timeouts are ignored.")]
public static MatchCollection Matches (string input, string pattern, RegexOptions options, TimeSpan matchTimeout)

Parameters

input
The string to search for a match.
pattern
The regular expression pattern to match.
options
A bitwise combination of the enumeration values that specify options for matching.
matchTimeout
A time-out interval, or Regex.InfiniteMatchTimeout to indicate that the method should not time out.

Returns

A collection of the System.Text.RegularExpressions.Match objects found by the search. If no matches are found, the method returns an empty collection object.

Remarks

The Regex.Matches(string, string, RegexOptions, TimeSpan) method is similar to the Regex.Match(string, string, RegexOptions, TimeSpan) method, except that it returns information about all the matches found in the input string, instead of a single match. It is equivalent to the following code:

code reference: System.Text.RegularExpressions.Regex.Matches#10

The static Matches methods are equivalent to constructing a System.Text.RegularExpressions.Regex object with the specified regular expression pattern and calling the instance method Matches.

The pattern parameter consists of regular expression language elements that symbolically describe the string to match. For more information about regular expressions, see .NET Framework Regular Expressions and Regular Expression Language Elements.

The Regex.Matches(string, int) method uses lazy evaluation to populate the returned System.Text.RegularExpressions.MatchCollection object. Accessing members of this collection such as MatchCollection.Count and MatchCollection.CopyTo(Array, int) causes the collection to be populated immediately. To take advantage of lazy evaluation, you should iterate the collection by using a construct such as foreach in C# and For Each…Next in Visual Basic.

Because of its lazy evaluation, calling the Regex.Matches(string, string, RegexOptions, TimeSpan) method does not throw a System.Text.RegularExpressions.RegexMatchTimeoutException exception. However, an exception is thrown when an operation is performed on the System.Text.RegularExpressions.MatchCollection object returned by this method, if a matching operation exceeds this time-out interval specified by thematchTimeout parameter.

Requirements

Namespace: System.Text.RegularExpressions
Assembly: System (in System.dll)
Assembly Versions: 4.0.0.0