From the course: C# and .NET Essential Training

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Using RegEx timeouts

Using RegEx timeouts

- [Instructor] One of the things you need to be really careful about when working with regular expressions is that they can be an unexpected source of potential security issues or other program problems. So for example, if your program works with text that comes from outside your app or outside your organization, then it's not that hard to create a text string that can hang your program resulting in a type of denial of service attack. So one way to help guard against this is by using timeouts to make sure that your Regexes don't hang the program. So let's see how to do this. Right here in my example code, in the timeouts folder I have an example string of content, right? It's this long string of A characters, and you can see that I'm also including the regular expressions, name space, along with the system diagnostics name space. The diagnostics name space gives me access to this stopwatch class, so I can see how…

Contents