The exception that is thrown when the execution time of a regular expression pattern-matching method exceeds its time-out interval.
See Also: RegexMatchTimeoutException Members
The presence of a System.Text.RegularExpressions.RegexMatchTimeoutException exception generally indicates one of the following conditions:
The regular expression engine is backtracking excessively as it attempts to match the input text to the regular expression pattern.
The time-out interval has been set too low, especially given high machine load.
The way in which an exception handler handles an exception depends on the cause of the exception:
If the time-out results from excessive backtracking, your exception handler should abandon the attempt to match the input and inform the user that a time-out has occurred in the regular expression pattern-matching method. If possible, information about the regular expression pattern, which is available from the RegexMatchTimeoutException.Pattern property, and the input that caused excessive backtracking, which is available from the RegexMatchTimeoutException.Input property, should be logged so that the issue can be investigated and the regular expression pattern modified. Time-outs due to excessive backtracking are always reproducible.
If the time-out results from setting the time-out threshold too low, you can increase the time-out interval and retry the matching operation. The current time-out interval is available from the RegexMatchTimeoutException.MatchTimeout property. When a System.Text.RegularExpressions.RegexMatchTimeoutException exception is thrown, the regular expression engine maintains its state so that any future invocations return the same result, as if the exception did not occur. The recommended pattern is to wait for a brief, random time interval after the exception is thrown before calling the matching method again. This can be repeated several times. However, the number of repetitions should be small in case the time-out is caused by excessive backtracking.
The example in the next section illustrates both techniques for handling a System.Text.RegularExpressions.RegexMatchTimeoutException.