vb.Net - Regular Expression Tester

Every now and then I find another use for a regular expression. For those not familiar with regular expressions, they can be as cryptic to read as strings of Greek letters. Simply put, regular expressions are just patterns. If you've ever used the DOS command shell dir command then you have likely used patterns, albeit simple ones. For example:

dir d:\temp\pic*.jpg

lists all files in the given folder that start with the letters pic and end with a .jpg extension. While the dir command allows only ? and * wildcards, regular expressions allow you to do so much more. They are frequently used to validate user input. There are patterns that match valid email addresses, social insurance numbers, phone numbers, etc. A common problem for beginners (or even professionals, for that matter) is figuring out what pattern to use. There are commercial programs, such as PowerGrep, available for testing regular expressions, but, being the cheap sort that I am, I decided to save a few bucks and just roll my own. It's not as flashy or feature rich as PowerGrep, or the tool that comes with Komodo Edit, but it is free. The code was written in vb.Net 2017. The entire project is attached as a zip file.

When you run it, you will see a minimal GUI consisting of a single-line textbox where you can type a pattern, two option boxes, and a multi-line rich textbox where you can enter (type or paste) text for testing. Feedback is real time. If you start by pasting one or more lines of text into the lower box, you will see what strings match the entered pattern, with matching string dynamically changing as you modify the pattern. Because the matches change as you enter the pattern, it may happen that the pattern will be in valid in mid-entry. For example, if you want to enter a character class such as


the pattern will become invalid as soon as you type [ and will not become valid until you enter ]. While the pattern is invalid it will be displayed in red and matching will stop. When the pattern becomes valid it will be displayed in black and dynamic matching will resume.

Pressing F1 at any time will cause a non-modal window to open displaying some brief notes about regular expression patterns. Please note that there is no absolute standard for regular expression syntax. This project, by necessity, follows the .Net core standard.

The two options are Multi-Line and Ignore Case. The first option controls how pattern matching handles end-of-line ($) markers and is best left checked for multi-line text. The second option is self-explanatory.

This is a first draft and will be modified as I add features or find problems. Constructive suggestions/feedback is always welcome.

An excellent resource for anyone wishing to learn more about regular expressions is "Beginning Regular Expressions" by Andrew Watt, ISBN: 0-7645-7489-2. Publised by Wrox Press/Wiley.

'please see attached project file
About the Author

I completed my Computer Science degree at the University of Manitoba in 1976. I did two and a half years of programming in medical research followed by twenty-nine years at Manitoba Hydro (electric utility). Most of that was spent on doing development and maintenance on an AGC/SCADA (real-time programming/process control) system. The last ten years of that was spent doing application and infrastructure support and development. I have programmed in FORTRAN (mostly), APL, PL/1, COBOL, Lisp, SNOBOL, ALGOL, Assembler (several flavours), C, C++, Paradox, VB, vbScript and more recently, Python. I am married with two grown children of whom I am very proud, and a most beautiful wife. I am currently retired (and loving it).

Another useful tool is Regexper where you enter a regular expression and it displays it in railroad diagram style. For example, a Mastercard credit card number pattern


displays as


Newer version also displays detailed information of matches, groups and captures in listview details format.

Newer version posted. This version has two changes.

  1. Uses a splitter control for the lower two panels for easier sizing
  2. Does not report matches with a length of zero (faster display)