Regex.Match Method (String, String, RegexOptions)
Microsoft Silverlight will reach end of support after October 2021. Learn more.
Searches the input string for the first occurrence of the regular expression supplied in a pattern parameter with matching options supplied in an options parameter.
Namespace: System.Text.RegularExpressions
Assembly: System (in System.dll)
Syntax
'Declaration
Public Shared Function Match ( _
input As String, _
pattern As String, _
options As RegexOptions _
) As Match
public static Match Match(
string input,
string pattern,
RegexOptions options
)
Parameters
- input
Type: System.String
The string to search for a match.
- pattern
Type: System.String
The regular expression pattern to match.
- options
Type: System.Text.RegularExpressions.RegexOptions
A bitwise combination of the enumeration values.
Return Value
Type: System.Text.RegularExpressions.Match
An object that contains information about the match.
Exceptions
Exception | Condition |
---|---|
ArgumentException | A regular expression parsing error occurred. |
ArgumentNullException | input is nulla null reference (Nothing in Visual Basic). -or- pattern is nulla null reference (Nothing in Visual Basic). |
ArgumentOutOfRangeException | options is not a valid bitwise combination of RegexOptions values. |
Remarks
The static Match methods are equivalent to constructing a Regex object with the specified 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.
If you want to restrict a match so it does not scan, anchor the regular expression with a \G (at the left for a left-to-right pattern, or at the right for a right-to-left pattern). This restricts the match so it must start exactly at startpos.
When a Regex is left-to-right (the default), the match and the scan proceed rightward, starting at the character at startat. When a Regex is right-to-left (constructed with the RightToLeft option enabled), the match and scan are in the opposite direction and begin with the character at startat -1.
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 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.
Version Information
Silverlight
Supported in: 5, 4, 3
Silverlight for Windows Phone
Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0
XNA Framework
Supported in: Xbox 360, Windows Phone OS 7.0
Platforms
For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.
See Also