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

Computer languages in which I have developed applications

Assembler (DEC, Data General, 8080, GE, SEL, IBM 360)
Borland Paradox

1 Month
Discussion Span
Last Post by Reverend Jim

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


Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.