Pattern Matching

At some point everyone has written code to test values that match patterns. There are many different ways this can be done. Typical examples, include string handling or using the myriad of other algorithms available. Recently, I have been working the Regular Expressions available within .NET. I am pretty impressed with their simplicity and power….

0

Validating Zip Code

I was recently putting together some proof of concept for a customer and realized that I hadn’t posted one of the common Regular Expressions that I had been using. Validating a Zip Code: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click        ‘ Invalid Zip code        ‘Dim strZip As String = “AB123”        …

0

Finding a Value

Character matching is one of the most powerful features of regular expressions. They allow the developer to quickly find certain patterns and characters within strings. The “.” is one of the most important and easiest to use examples of this. The period is a special character with regular expressions that allows the search to find…

0

Validating a Phone Number

Simple example of validating a phone number: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click      ‘ Invalid phone number     ‘Dim strPhone As String = “123456789”     ‘ valid phone number    Dim strPhone As String = “(123) 456-7890”    Dim regexp As New Regex((“^\(?\d{3}\)?\s|-\d{3}-\d{4}$”))     If regexp.IsMatch(strPhone) Then           MsgBox(“Valid Phone Number”)    Else          MsgBox(“Invalid Phone…

3

Validating Email

While doing some coding the other day I needed an expression to validate email addresses. The trick was that it had to be flexible enough to handle emails in the format of username@company.com and firstname.lastname@company.com.   Imports System.Text.RegularExpressions Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click         Dim strEmail As String…

1

What is a Regular Expression

Regular expressions are about finding and changing patterns. One of the most common that I always find is the need to reformat a “proper name”. It seems that every conversion program that I get involved in requires the re-ordering of the name. Regular expressions offer something called a backreference that can help with this. Basically,…

0

Welcome Back

Welcome to the new site! I am working on moving the older content back.   Stay Tuned

5