Is there an easy way to test a Regular Expression for validity?

One of my controls lets the user type a Regular Expression that is used to evaluate the contents of another control.  Currently, I am testing to see if the expression is valid using exception handling like so:

Try
    testRegEx = New RegEx(userText)
Catch ex As Exception
    'Invalid Regular Expression
 End Try

This works, but it seems wrong.  Exceptions are for failure-type scenarios, not common error checking.  Is there a way to evaluate a string and determine if it is a valid Regular Expression without creating my own RegEx parser?
LVL 2
GohdanTheMoblinAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ignacio Soler GarciaSolution Architech & Technical LeadCommented:
To me this way looks good, but you can use also the ErrorProvider control. Exception are used to catch any kind of error on the execution of code and a bad formed string is a kind of error in the execution of the code.

SoMoS
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
GohdanTheMoblinAuthor Commented:
Yeah, I thought as much.  It'd be nice if there was a TryParse method.  The exception provides poor performance and I'd like a different way, but I guess it's all there is.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.