RegexCompilationInfo::MatchTimeout Property
Gets or sets the regular expression's default time-out interval.
Assembly: System (in System.dll)
Property Value
Type: System::TimeSpanThe default maximum time interval that can elapse in a pattern-matching operation before a RegexMatchTimeoutException is thrown, or Regex::InfiniteMatchTimeout if time-outs are disabled.
The MatchTimeout property defines the default time-out interval for the compiled regular expression. This value represents the approximate amount of time that a compiled regular expression 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.
Important |
|---|
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 the compiled regular expression's class constructor. |
You can assign a default time-out value to a RegexCompilationInfo object in any of the following ways:
By calling the AppDomain::SetData method and providing the string representation of a TimeSpan value for the "REGEX_DEFAULT_MATCH_TIMEOUT" property.
By calling the RegexCompilationInfo(String^, RegexOptions, String^, String^, Boolean, TimeSpan) constructor and providing a value for the matchTimeout parameter.
By setting the value of this property.
To set a reasonable time-out interval, consider the following factors:
The length and complexity of the regular expression pattern. Longer and more complex regular expressions require more time than shorter and simpler ones.
The expected machine load. Processing takes more time on systems with high CPU and memory utilization.
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.
Available since 4.5

The regular expression pattern (\w)\1+ is defined as shown in the following table.
Pattern
Description
(\w)
Match any word character and assign it to the first capturing group.
\1+
Match one or more occurrences of the value of the first captured group.