Regex.Match Method (String, String)
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Searches the specified input string for the first occurrence of the regular expression supplied in the pattern parameter.
Assembly: System (in System.dll)
Parameters
- input
- Type: System.String
The string to search for a match.
- pattern
- Type: System.String
The regular expression pattern to match.
Return Value
Type: System.Text.RegularExpressions.MatchAn object that contains information about the match.
| Exception | Condition |
|---|---|
| ArgumentException | A regular expression parsing error occurred. |
| ArgumentNullException | input is null. -or- pattern is null. |
The static Match methods are equivalent to constructing a Regex object with the specified regular expression pattern and calling the instance method Match.
The pattern parameter consists of various regular expression language elements that symbolically describe the string to match. For more information about regular expressions, see Regular Expression Language Elements in the .NET Framework documentation.
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 successful, 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 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) method.