次の方法で共有


Regex.Match Method (String, String)

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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)

Syntax

'Declaration
Public Shared Function Match ( _
    input As String, _
    pattern As String _
) As Match
public static Match Match(
    string input,
    string pattern
)

Parameters

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

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

Remarks

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.

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.