Click below for Step by Step and Interview Q & A (dotnetinter) wrote,
Click below for Step by Step and Interview Q & A
dotnetinter

.NET interview questions: - What is time out support in regex (regular expression)?

Some of the regular expressions are very complex and they can take lot of time to evaluate.
For instance below is a simple regular expression.

re1

If someone inputs a huge number as shown in the below code snippet. It will take more than a minute to resolve the expression leading to lot of load on the application. So we would like to give a time out on the expression. So if the validation takes more than a specific interval we would like the application to give up and move ahead.

re2

In .NET 4.5 we can now provide the timeout value as parameter on the constructor. For instance in the below code we have provided 2 seconds timeout on the regex (regular expression). So if it exceeds more than 2 second “regexMatchTimeOutException” will occur.

re3

Also see following .NET interview questions video on regular expressions & can we see some practical demonstrations: -

Tags: .net, .net interview questions, c#, csharp interview questions, it interview questions, programming interview questions, regex, regular expression
Subscribe

  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments