Export (0) Print
Expand All
1 out of 2 rated this helpful - Rate this topic

Regex.Match Method (String, String, RegexOptions)

Updated: July 2009

Searches the input string for the first occurrence of the regular expression supplied in a pattern parameter, using the matching options supplied in the options parameter.

Namespace:  System.Text.RegularExpressions
Assembly:  System (in System.dll)
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 OR combination of the enumeration values.

Return Value

Type: System.Text.RegularExpressions.Match
An object that contains information about the match.
ExceptionCondition
ArgumentException

A regular expression parsing error has occurred.

ArgumentNullException

input is null.

-or-

pattern is null.

ArgumentOutOfRangeException

options is not a valid bitwise combination of RegexOptions values.

The static Match(String, String, RegexOptions) method is equivalent to constructing a Regex object with the Regex(String, RegexOptions) constructor and calling the instance Match(String) method.

The pattern parameter consists of various 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 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.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0

XNA Framework

Supported in: 3.0, 2.0, 1.0

Date

History

Reason

July 2009

Included additional exception information.

Content bug fix.

October 2008

Expanded the Remarks section.

Customer feedback.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.