Searches the input string for the first occurrence of the specified regular expression, using the specified matching options and time-out interval.
- input
- The string to search for a match.
- pattern
- The regular expression pattern to match.
- options
- A bitwise combination of the enumeration values that provide options for matching.
- matchTimeout
- A time-out interval, or Regex.InfiniteMatchTimeout to indicate that the method should not time out.
An object that contains information about the match.
The Regex.Match(string, string, RegexOptions, TimeSpan) 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.
The static Regex.Match(string, string, RegexOptions, TimeSpan) method is equivalent to constructing a System.Text.RegularExpressions.Regex object with the Regex.#ctor(string, RegexOptions, TimeSpan) constructor and calling the instance Regex.Match(string) method.
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.
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 found 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, string, RegexOptions) method.
The matchTimeout parameter specifies how long a pattern matching method should try to find a match before it times out. Setting a time-out interval prevents regular expressions that rely on excessive backtracking from appearing to stop responding when they process input that contains near matches. For more information, see Best Practices for Regular Expressions in the .NET Framework and Backtracking. If no match is found in that time interval, the method throws a System.Text.RegularExpressions.RegexMatchTimeoutException exception. matchTimeout overrides any default time-out value defined for the application domain in which the method executes.