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. The downside is that many times they can be quite the mental puzzle to figure out. I can easily understand how these can be overwhelming to understand and use. Over the next couple of weeks, I am planning on blogging about some of these that I have been playing with and collecting.


Here is a simple example that checks to see if a string contains a specific phrase:


Imports System.Text.RegularExpressions


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim r As Regex = New Regex(“(\w+)\s+(blue)”)

        Dim comstring As String = “blue ball”


        If r.IsMatch(comstring) Then

            MsgBox(“Match Successful”)


            MsgBox(“Match failed”)

        End If


    End Sub


Comments (0)