Export (0) Print
Expand All

Regex.Match Method (String, String)

Searches the specified input string for the first occurrence of the regular expression supplied in the pattern parameter.

Namespace:  System.Text.RegularExpressions
Assembly:  System (in System.dll)

public static Match Match(
	string input,
	string pattern
)

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.Match
An object that contains information about the match.

ExceptionCondition
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.

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

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions

ADD
Show:
© 2014 Microsoft