Welcome to Professional ASP.NET - Chris Love's Official Blog Sign in | Join | Help

Chris Love's Official ASP.NET Blog

Chris Love's Helpful tips, tricks and pragmatic development knowledge for the ASP.NET world.
Add to Technorati Favorites


ASP Insider Follow Me On Twitter
Regular Expression Visualizer - A Must Have Tool

This week I saw a twitter from Roy Osherove about a new Regular Expression Visualizer he built. If you do not know Roy yet, he is a very smart .NET developer for TypeMock and has done some great work with regular expression tools, such as Regulazy and The Regulator. If you are not familiar with Visualizers then you should get to know how they work.

A Visualizer is simple a tool inside of Visual Studio that allows you to see the data in an object. Custom Visualizers can be created to provide a richer view of an object than the built-in String visualizer where you can just drill into the specific items of an object. The idea being you will be able to have a better experience visualizing the object. In the case of Roy's regular expression visualizer you get a more organized view into how a regular expression is working in the application.

Once you download the zip package containing the components for the Regular Expression Visualizer you can look at the ReadMe.txt file for instructions to install the visualizer. Basically you need to extract a set of dlls to the 'My Documents\Visual Studio 2008\Visualizers' folder. This will install the visualizer in Visual Studio for instance use.

Roy wrote a very simple test to verify the visualizer is installed, but I wanted to take it to a more practical example for you. I changed the example to check a phone number to see if it is valid. The example uses a regular expression to extract the parts of a valid phone number. It then checks to see if there are any valid matches and returns true.

I set a breakpoint in the code before it would return true or false on a match. This allows you to roll the mouse over the matches collection. Here you will see a magnifying glass in the inline watch window. This can then be clicked to display a menu of possible visualizers, in this case the Regular Expression Visualizer. By selecting this visualizer it will display a special dialog.

This dialog provides a breakdown not only of how the regular expression works, but allows you to manipulate how the expression is applied so you can see how it affects the string being parsed. I thing the Pattern Desc tab is extremely useful to see the logic of how a regular expression is executed like no where else I have ever seen. This alone is a great experience for anyone new to regular expressions. It is a great feature to debug a regular expression.

 

In the top left corner there is a Matches Tab, which shows all the strings contained in the source that match the regular expression. This provides an expandable view into the pieces that match the expression.

When it is all said and done the Regular Expression Visulizer is a great tool for Visual Studio to help build and test regular expressions in .NET applications. I recommend this for any .NET programmer to add to their toolkit to be more productive.

Example Regular Expression Test Project

Share this post :
Posted: Wednesday, June 18, 2008 11:43 PM

by Chris Love

Comments

DotNetKicks.com said:

You've been kicked (a good thing) - Trackback from DotNetKicks.com

# June 18, 2008 11:48 PM

Jim Arthur said:

Sorry, you test project is returning a page not found error.
# June 19, 2008 9:01 AM

Chris Love said:

Sorry I put too many s's in the URL. ;)
# June 19, 2008 1:42 PM

Randy Walker Blog said:

You might want to skip this first paragraph if you are just looking for the RegEx Tools portion. I still
# June 19, 2008 4:47 PM

Lilyana Boneva said:

Very interesting. Too bad the links don't work any more.
# August 4, 2009 3:27 AM

Chris Love said:

# August 4, 2009 9:07 AM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS