Regex.Match Method (String, String, RegexOptions)
Searches the input string for the first occurrence of the specified regular expression, using the specified matching options.
Assembly: System (in System.dll)
The string to search for a match.
The regular expression pattern to match.
A bitwise combination of the enumeration values that provide options for matching.
Return ValueType: System.Text.RegularExpressions.Match
An object that contains information about the match.
A regular expression parsing error occurred.
input or pattern is null.
options is not a valid bitwise combination of RegexOptions values.
A time-out occurred. For more information about time-outs, see the Remarks section.
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 - Quick Reference.
You can determine whether the regular expression pattern has been found in the input string by checking the value of the returned Match object's Success property. If a match is found, the returned Match object's 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 Match object's NextMatch method. You can also retrieve all matches in a single method call by calling the Regex.Matches(String, String, RegexOptions) method.
The RegexMatchTimeoutException exception is thrown if the execution time of the matching operation exceeds the time-out interval specified for the application domain in which the method is called. If no time-out is defined in the application domain's properties, or if the time-out value is Regex.InfiniteMatchTimeout, no exception is thrown.
Notes to Callers:
This method times out after an interval that is equal to the default time-out value of the application domain in which it is called. If a time-out value has not been defined for the application domain, the value Regex.InfiniteMatchTimeout, which prevents the method from timing out, is used. The recommended static method for retrieving a pattern match is Regex.Match(String, String), which lets you set the time-out interval.
The following example defines a regular expression that matches words beginning with the letter "a". It uses the RegexOptions.IgnoreCase option to ensure that the regular expression locates words beginning with both an uppercase "a" and a lowercase "a".
Available since 8
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Available since 8.1