Introduction

With RegEx Tester, you can fully develop and test your regular expression against a target text.Its UI is designed to aid you in the RegEx development; especially the big and complex ones.It uses and supports almost ALL of the features available in the .NET RegEx class.About this article's writing, I have to tell you that English is not my native language and that I did my best in the redaction, grammar and spelling. You may and will find writing errors, so please tell me about them so that I can correct them.

Feature List

If you have an idea for a new feature, you could code it up and send it to me by email and I will add it here with the proper credits for your work. If you don't know how to properly code that idea, comment about it and other people (or me) can do it. Let's collaborate.

Asynchronous execution enabling the user to abort the execution. Even if you make a Catastrophic Backtracking mess. [by Pablo Oses]

Indented Input mode which strips \r \n \t \v and spaces before execution. This allows you to write those ugly, long and cryptic RegExs in an indented and spaced fashion. [by Pablo Oses]

Replace mode which enables the use of RegEx.Replace() function [by Pablo Oses]

Mono Compatible which makes it capable of running on Linux [by Pablo Oses]

Test Text highlighting based on results selection [by Davide Mauri]

F5 Hot Key to run the Test without changing the cursor position or selection. Get off of that Mouse ! [by Pablo Oses]

Listing of the matches showing position, length and anonymous or named capture groups [by Davide Mauri and Pablo Oses]

What is Special About this Program?

As balazs_hideghety said in his comment, there are other popular, and great programs like RegEx buddy or Expresso that are extremely powerful and seem to be the last word on RegEx development and testing, but I still use this tool. Why? I needed a tool that helped me design HTML Extraction RegExs. For example (as of May 2009), if you evaluate this...

... against the HTML source of this page, you would be parsing and extracting in only one operation all the comments inside this page with its corresponding title, body, date, user, etc. RegExs are really powerful when you are extracting data of real world websites. But the problem is that the RegExs needed are looooooong and extremely cryptic. You really start to need some spacing and indentation there to unofbuscate it and you need a big window with a lot of space and a test textbox able to handle big raw HTML documents so there's when this tool turns out to be really useful.

The same RegEx while I was developing it in RegExTester looked like this:

The Asynchronous Execution Feature. Where the Fun Starts!

I first coded it using a BackgroundWorker but I had to throw it out because it seems that it's only useful when you want to abort a long loop that is IN your code... But it doesn't help you when you call an external function that takes too long to complete.

So I re-coded it from scratch using a more low level Thread managing that resulted in being more simple and clear than the previous technique once it was done.

private Thread worker; // The worker that really does the execution in a separate thread.privatevoid MainForm_Load(object sender, System.EventArgs e)
{
// This is a critical line.// It allows the other thread to access the controls of this class/object.
Control.CheckForIllegalCrossThreadCalls = false;
}
///<summary>/// Handle the multiple behaviors of the Test button based on its text
///</summary>privatevoid btnTest_Click(object sender, System.EventArgs e)
{
if (btnTest.Text == STOPPED_MODE_BUTTON_TEXT)
{
StartTest();
}
elseif (btnTest.Text == RUNNING_MODE_BUTTON_TEXT)
{
AbortTest();
}
}
///<summary>/// Prepare and launch the asynchronous execution using another thread
///</summary>privatevoid StartTest()
{
// Creates the separate Thread for executing the Test
worker = new Thread(AsyncTest);
// After this instruction if the worker hangs and this thread exits,// then nobody has to wait for the worker to finish. // (e.g. The worker will be aborted if the user wants to close the app.)
worker.IsBackground = true;
// Start the Asynchronous Test function
worker.Start();
}
///<summary>/// Instructs to abort the asynchronous execution of the Test.
///</summary>privatevoid AbortTest()
{
// This generates a ThreadAbortException at the worker function AsyncTest()if (worker.IsAlive) worker.Abort();
}
///<summary>/// This is the core of the app. The RegEx execution and processing function.
/// It's being run on a separated thread.
///</summary>privatevoid AsyncTest()
{
// Every line in this function is susceptible of a ThreadAbortException// which is how the user is able to stop it.try
{
sbpStatus.Text = "Test running...";
// ***************************************// Here is the code that you already read // in the previous section of this article// [The core of the program: AsyncTest()]// ***************************************
sbpStatus.Text = "Test success.";
}
catch (ThreadAbortException)
{
sbpStatus.Text = "Test aborted by the user.";
}
catch (Exception e)
{
sbpStatus.Text = "Test aborted by an error.";
// Any other Exception is shown to the user
MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
// Restore the btnText functionality
btnTest.Text = STOPPED_MODE_BUTTON_TEXT;
}
}

Program's History

This tool was originally written by Davide Mauri (2003). I used it A LOT at work and for personal projects. Thanks to the fact that it was open source, I started to add new features that I needed. One day the program was so different that I wanted to give all these enhancements to Davide so I contacted him by email and he gave me permission to re-release it and gave me the link to Kurt Griffith's version of the program (2006). I made a mix of his and my enhancements and polished the UI.