Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Regex.Regex(String, RegexOptions) Constructor

Initializes and compiles a new instance of the Regex class for the specified regular expression, with options that modify the pattern.

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

public Regex (
	string pattern,
	RegexOptions options
)
public Regex (
	String pattern, 
	RegexOptions options
)
public function Regex (
	pattern : String, 
	options : RegexOptions
)
Not applicable.

Parameters

pattern

The regular expression pattern to match.

options

A bitwise OR combination of RegexOptions enumeration values.

Exception typeCondition

ArgumentException

Regular expression parsing error.

ArgumentNullException

pattern is a null reference (Nothing in Visual Basic).

ArgumentOutOfRangeException

options contains an invalid flag.

The pattern parameter consists of various regular expression language elements that symbolically describe the string to match. For more information about regular expressions, see the .NET Framework Regular Expressions and Regular Expression Language Elements topics.

A Regex object is immutable, which means that it can be used only for the match parameters defined when it is created. It can be used any number of times without being recompiled, however.

The following example illustrates how to use this constructor to instantiate a regular expression that matches any word that begins with the letters "a" or "t".

Note that the match collection includes the word “The” that begins the text because the options parameter has defined case-insensitive comparisons.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0

Community Additions

Show: