Check if a string is a valid RegEx Pattern VB.NET

regex, vb.net

Solution

No, there is no other solution (you could of course reimplement the regex parser, but that would be an error-prone hell of work).

I would prefer catching the specific `ArgumentException` that the `Regex` constructor throws if the regex is invalid other than just `Exception`.

Problem

ok I have the following strings ``` "^[a-z]*$" ``` and ``` "a-z" ``` now what I want with those two strings is to check if they are valid Regular Expressions strings in VB.NET. I really have no idea how can I make it... but I tried something below ``` Try Dim regex As Regex = New Regex("a-z") Return "valid regex" Catch ex As Exception Return "not valid regex" End Try ``` but my solution above seems not really good. Is there much better solution?

Original source