Regex and LINQPad

Recently, I was working with a customer who needed dynamic worksheet names in their Excel workbooks.  With ExcelWriter this is no problem!  Since the input was coming from the end users, I need to perform some validation on the input to make sure it conforms to Excel’s restrictions on what a valid worksheet name can be.

Valid Worksheet Names in Excel

  1. They cannot exceed 31 characters.
  2. They cannot contain the following characters: \ / ? * [ ]
  3. The name cannot be the same as another Worksheet in the Workbook.
  4. The worksheet name cannot be blank

In this case I am interested in #2 and dealing with invalid characters.  I know that Regex is the best option for this–when I’m working with Regex, I often find testing to be a pain. I‘ll open Visual Studio, create a console application and write some code to test my patterns.  Just when I was starting to get fed up with all these random testing console applications in my projects directory, I remembered an application called LINQPad that my co-work Sean told me about. LINQPad is a standalone C#/VB/F# scratch pad that can instantly execute code. The output is displayed in a rich format.

So I came up with the following Regex Pattern:


and wanted to test it.  Using LINQPad this was a breeze.  I typed my pattern into LINQPad and pressed “Execute,” (the green arrow) which allowed me to see the output.

It worked perfectly.

LINQPad can be used for much more than just Regular Expression testing, though I won’t go into the details here. I encourage you to read about all the features at:

Now I can spend more time focusing on my work and less time setting up.

Related posts: