Share via


Matches Method (String, String)

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

Searches the specified input string for all occurrences of a specified regular expression.

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

Syntax

'Declaration
Public Shared Function Matches ( _
    input As String, _
    pattern As String _
) As MatchCollection
public static MatchCollection Matches(
    string input,
    string pattern
)
public:
static MatchCollection^ Matches(
    String^ input, 
    String^ pattern
)
static member Matches : 
        input:string * 
        pattern:string -> MatchCollection 
public static function Matches(
    input : String, 
    pattern : String
) : MatchCollection

Parameters

Return Value

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

Remarks

The Matches(String, String) method is similar to the Match(String, String) method, except that it returns information about all the matches found in the input string, instead of a single match.

The static Matches methods are equivalent to constructing a 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.

The Matches method uses lazy evaluation to populate the returned MatchCollection object. Accessing members of this collection such as MatchCollection..::..Count and MatchCollection..::..CopyTo 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 ForEach…Next in Visual Basic.

Because of its lazy evaluation, calling the Matches(String, String) method does not throw a RegexMatchTimeoutException exception. However, the exception is thrown when an operation is performed on the MatchCollection object returned by this method, if a time-out interval is defined by the "REGEX_DEFAULT_MATCH_TIMEOUT" property of the current application ___domain and a matching operation exceeds this time-out interval.

.NET Framework Security

See Also

Reference

Regex Class

Matches Overload

System.Text.RegularExpressions Namespace