RegexOptions Enumeration

 

Provides enumerated values to use to set regular expression options.

This enumeration has a FlagsAttribute attribute that allows a bitwise combination of its member values.

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

[FlagsAttribute]
public enum class RegexOptions

Member nameDescription
Compiled

Specifies that the regular expression is compiled to an assembly. This yields faster execution but increases startup time. This value should not be assigned to the Options property when calling the CompileToAssembly method. For more information, see the "Compiled Regular Expressions" section in the Regular Expression Options topic.

CultureInvariant

Specifies that cultural differences in language is ignored. For more information, see the "Comparison Using the Invariant Culture" section in the Regular Expression Options topic.

ECMAScript

Enables ECMAScript-compliant behavior for the expression. This value can be used only in conjunction with the IgnoreCase, Multiline, and Compiled values. The use of this value with any other values results in an exception.

For more information on the RegexOptions::ECMAScript option, see the "ECMAScript Matching Behavior" section in the Regular Expression Options topic.

ExplicitCapture

Specifies that the only valid captures are explicitly named or numbered groups of the form (?<name>…). This allows unnamed parentheses to act as noncapturing groups without the syntactic clumsiness of the expression (?:…). For more information, see the "Explicit Captures Only" section in the Regular Expression Options topic.

IgnoreCase

Specifies case-insensitive matching. For more information, see the "Case-Insensitive Matching " section in the Regular Expression Options topic.

IgnorePatternWhitespace

Eliminates unescaped white space from the pattern and enables comments marked with #. However, this value does not affect or eliminate white space in , numeric , or tokens that mark the beginning of individual . For more information, see the "Ignore White Space" section of the Regular Expression Options topic.

Multiline

Multiline mode. Changes the meaning of ^ and $ so they match at the beginning and end, respectively, of any line, and not just the beginning and end of the entire string. For more information, see the "Multiline Mode" section in the Regular Expression Options topic.

None

Specifies that no options are set. For more information about the default behavior of the regular expression engine, see the "Default Options" section in the Regular Expression Options topic.

RightToLeft

Specifies that the search will be from right to left instead of from left to right. For more information, see the "Right-to-Left Mode" section in the Regular Expression Options topic.

Singleline

Specifies single-line mode. Changes the meaning of the dot (.) so it matches every character (instead of every character except \n). For more information, see the "Single-line Mode" section in the Regular Expression Options topic.

A RegexOptions value can be provided as a parameter to the following members of the Regex class:

A RegexOptions value can also be supplied as a parameter to the RegexCompilationInfo constructor, or it can be assigned directly to the Options property. The resulting RegexCompilationInfo object is then used in the call to the CompileToAssembly method.

Several options provided by members of the RegexOptions enumeration (in particular, by its RegexOptions::ExplicitCapture, RegexOptions::IgnoreCase, RegexOptions::Multiline, and RegexOptions::Singleline members) can instead be provided by using an inline option character in the regular expression pattern. For details, see Regular Expression Options.

The following example defines two regular expressions that identify repeated words in text but that are instantiated using different RegexOptions values. The first regular expression is case-insensitive; case is ignored when determining whether a word is identical to the preceding word. The second regular expression is case-sensitive; a word must match the case of the preceding word exactly to be considered a duplicate.

No code example is currently available or this language may not be supported.

Universal Windows Platform
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top
Show: