In a .NET application (written in C#) I have a UI with a list and a text box used to enter a filter string to filter what is displayed in the list. I refresh the filter as the user types.
I now want to allow use of regular expressions in the filter string, which poses a problem. As the user types the expression it may be invalid, for instance between the time that an opening bracket is typed and the time that the closing bracket is typed. Newing up a Regex with an invalid expression throws an exception and I want to prevent this. One way is to catch the exception but I was wondering if there is some way to check that the expression is a valid regular expression without actually trying to new up a Regex with it.