I talked briefly about regular expressions in .NET Framework here, how you can test for a match and how to extract or replace a matched group, or matched substring if you may. The examples there used a named group to extract a matched group (e.g. ?<proto>, ?<port>, etc…). It’s worth mentioning that you can also extract a matched group using $ (e.g. $0, $1, $2, … $n, where $0 is the whole string that was matched, $1 is the first matched group, $2, the second matched group, and so on…).
Also it would be nice if you have a tool you can use to test out your regular expressions instead of testing it out in your code, compiling it, and running it. Well there are tools out there available for you but the ones I liked the most are online tools and are listed below.
Online Regular Expression Tester
- A Better .NET Regular Expression Tester – it’s user interface is not fancy but it does the job well.
- Regex Storm .Net – this one is a much better user interface and does the job too.
- RegExr – an online tool to learn, build, & test. It has a cheatsheet and a very good sample text to test your regex.
Online Quick Reference Guides