FastSharp - Rapid C# Scripting
Nick Clarke | February 17, 2008Today I had to update a regular expression that I have not touched in two years!
On first look I got the old hhmm where do I start
(?<Protocol>\w+):\/\/(?<Subdomain>\w+)\.(?<Domain>\w+)\.(?<tlDomain>[\w.]+)/(?<File>.*)
This matches:
http://subdomain.url.com/Default.aspx
And breaks it into:
Protocol: http
Subdomain: subdomain
Domain: url
tlDomain: com
File: Default.aspx
But the problem starts when you have a - (dash) in the subdomain:
http://a-subdomain.url.com/Default.aspx
This of course fails as I use \w to break up the subdomain string, which just matches alphanumeric characters. All I need to do is to allow - as well as a-zA-Z0-9 (\w).
The final expression was:
(?<Protocol>\w+):\/\/(?<Subdomain>[\w-]+)\.(?<Domain>\w+)\.(?<tlDomain>[\w.]+)/(?<File>.*)
- Change marked in red
Simple change but testing this takes some time as I either have to run my complete application or write a small test program.
Last week Matt Manela on the msdn blog shared a great application that allows you to test C# code without having to even write a class or create a project.
FastSharp is a great tool for testing out some code. It even goes as far as checking for compilation errors.

This was caused by me not adding the correct library for the Regex class.
To fix this all I had to do was click settings and then add the using statement.
using System.Text.RegularExpressions;

My little code snippet then ran fine and I was able to test and adapt my change very fast.
Great tool be sure to check it out + for more in depth into why and how it was coded see Matt’s post.











