System.Text.RegularExpressions.Regex.Match Method

Searches the specified input string for the first occurrence of the regular expression specified in the System.Text.RegularExpressions.Regex constructor.

Syntax

public Match Match (string input)

Parameters

input
The string to search for a match.

Returns

An object that contains information about the match.

Remarks

The Regex.Match(string) method returns the first substring that matches a regular expression pattern in an input string. For information about the language elements used to build a regular expression pattern, see Regular Expression Language - Quick Reference.

You can determine whether the regular expression pattern has been found in the input string by checking the value of the returned System.Text.RegularExpressions.Match object's Group.Success property. If a match is found, the returned System.Text.RegularExpressions.Match object's Capture.Value property contains the substring from input that matches the regular expression pattern. If no match is found, its value is string.Empty.

This method returns the first substring in input that matches the regular expression pattern. You can retrieve subsequent matches by repeatedly calling the returned System.Text.RegularExpressions.Match object's Match.NextMatch method. You can also retrieve all matches in a single method call by calling the Regex.Matches(string) method.

The System.Text.RegularExpressions.RegexMatchTimeoutException exception is thrown if the execution time of the matching operation exceeds the time-out interval specified by the Regex.#ctor(string, RegexOptions, TimeSpan) constructor. If you do not set a time-out interval when you call the constructor, the exception is thrown if the operation exceeds any time-out value established for the application domain in which the System.Text.RegularExpressions.Regex object is created. If no time-out is defined in the System.Text.RegularExpressions.Regex constructor call or in the application domain's properties, or if the time-out value is Regex.InfiniteMatchTimeout, no exception is thrown.

Requirements

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