[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


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

Posted on 2004-11-14
Medium Priority
Last Modified: 2010-04-24
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:

    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?
Question by:GohdanTheMoblin

Accepted Solution

Ignacio Soler Garcia earned 500 total points
ID: 12582663
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.


Author Comment

ID: 12585417
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.

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question