RegexCompilationInfo Constructor (String^, RegexOptions, String^, String^, Boolean, TimeSpan)

.NET Framework (current version)

The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Initializes a new instance of the RegexCompilationInfo class that contains information about a regular expression with a specified time-out value to be included in an assembly.

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

	String^ pattern,
	RegexOptions options,
	String^ name,
	String^ fullnamespace,
	bool ispublic,
	TimeSpan matchTimeout


Type: System::String^

The regular expression to compile.

Type: System.Text.RegularExpressions::RegexOptions

The regular expression options to use when compiling the regular expression.

Type: System::String^

The name of the type that represents the compiled regular expression.

Type: System::String^

The namespace to which the new type belongs.

Type: System::Boolean

true to make the compiled regular expression publicly visible; otherwise, false.

Type: System::TimeSpan

The default time-out interval for the regular expression.

Exception Condition

name is String::Empty.


pattern is null.


name is null.


fullnamespace is null.


matchTimeout is negative, zero, or greater than approximately 24 days.

Each parameter of the RegexCompilationInfo(String^, RegexOptions, String^, String^, Boolean) constructor directly corresponds to a property of the RegexCompilationInfo class. Because all properties are read/write, their values can also be assigned directly.

The CompileToAssembly method generates an assembly that contains compiled regular expressions. Therefore, you should not specify Compiled as one of the values of options.

If ispublic is true, the compiled regular expression class is given public accessibility. That is, it can be instantiated from code that executes in any assembly. If ispublic is false, the compiled regular expression class is given internal (in C#) or Friend (in Visual Basic) accessibility. That is, it can be instantiated only from code that executes in the same assembly as the regular expression class.

The matchTimeout parameter defines the default time-out interval for the compiled regular expression. This value represents the approximate amount of time that a compiled regular expression object will execute a single matching operation before the operation times out and the regular expression engine throws a RegexMatchTimeoutException exception during its next timing check. For additional information about the time-out value, see the MatchTimeout property.


We recommend that you always set a default time-out value for a compiled regular expression. Consumers of your regular expression library can override that time-out value by passing a TimeSpan value that represents the new time-out interval to this constructor overload.

The following example defines a single compiled regular expression named DuplicateChars that identifies two or more occurrences of the same character in an input string. The compiled regular expression has a default time-out of 2 seconds. When you execute the example, it creates a class library named RegexLib.dll that contains the compiled regular expression.

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

The regular expression pattern (\w)\1+ is defined as shown in the following table.




Match any word character and assign it to the first capturing group.


Match one or more occurrences of the value of the first captured group.

The following example uses the DuplicatedChars regular expression to identify duplicate characters in a string array. When it calls the DuplicatedChars constructor, it changes the time-out interval to .5 seconds.

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

.NET Framework
Available since 4.5
Return to top