In case this helps expediate solving the problem, here is my little test application I've been using (below is entire contents of the .vb file). The RegEx's are in red, bold font.
Lazer[tt]
Imports System.Text.RegularExpressions
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents RadioButton1 As System.Windows.Forms.RadioButton
Friend WithEvents RadioButton2 As System.Windows.Forms.RadioButton
Friend WithEvents RadioButton3 As System.Windows.Forms.RadioButton
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.TextBox2 = New System.Windows.Forms.TextBox
Me.Label1 = New System.Windows.Forms.Label
Me.RadioButton1 = New System.Windows.Forms.RadioButton
Me.RadioButton2 = New System.Windows.Forms.RadioButton
Me.RadioButton3 = New System.Windows.Forms.RadioButton
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(176, 384)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(320, 136)
Me.Button1.TabIndex = 0
Me.Button1.Text = "Count"
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(64, 40)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.TabIndex = 1
Me.TextBox1.Text = "IS"
'
'TextBox2
'
Me.TextBox2.Location = New System.Drawing.Point(64, 96)
Me.TextBox2.Multiline = True
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.Size = New System.Drawing.Size(496, 176)
Me.TextBox2.TabIndex = 2
Me.TextBox2.Text = "IS YOUR NAME JOHN? NO IT IS CHRIS. MAYBE ACTUALLY IT IS ISAAC. IT IS IT IS! I" & _
"S"
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(568, 424)
Me.Label1.Name = "Label1"
Me.Label1.TabIndex = 3
Me.Label1.Text = "(Total)"
'
'RadioButton1
'
Me.RadioButton1.Checked = True
Me.RadioButton1.Location = New System.Drawing.Point(248, 304)
Me.RadioButton1.Name = "RadioButton1"
Me.RadioButton1.Size = New System.Drawing.Size(104, 48)
Me.RadioButton1.TabIndex = 5
Me.RadioButton1.TabStop = True
Me.RadioButton1.Text = "Deb18's (modified) RegEx"
'
'RadioButton2
'
Me.RadioButton2.Location = New System.Drawing.Point(368, 312)
Me.RadioButton2.Name = "RadioButton2"
Me.RadioButton2.Size = New System.Drawing.Size(104, 40)
Me.RadioButton2.TabIndex = 6
Me.RadioButton2.Text = "RiverGuy's function"
'
'RadioButton3
'
Me.RadioButton3.Location = New System.Drawing.Point(496, 312)
Me.RadioButton3.Name = "RadioButton3"
Me.RadioButton3.Size = New System.Drawing.Size(136, 24)
Me.RadioButton3.TabIndex = 7
Me.RadioButton3.Text = "My original function"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(712, 581)
Me.Controls.Add(Me.RadioButton3)
Me.Controls.Add(Me.RadioButton2)
Me.Controls.Add(Me.RadioButton1)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.TextBox2)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.Button1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Function CountSubStr(ByVal InputText As String, ByVal CountStr As String) As Integer
'Dim MyRegEx As New Regex(" " & CountStr & "\W"
'Sunaj
Dim MyRegEx As New Regex("(\s|^)" & CountStr & "\W|$"
'Deb18
Dim Mc As MatchCollection = MyRegEx.Matches(InputText)
CountSubStr = Mc.Count
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If RadioButton1.Checked Then
Label1.Text = CountSubStr(TextBox2.Text, TextBox1.Text)
Else
If RadioButton3.Checked Then
Label1.Text = occurrences(TextBox1.Text, TextBox2.Text)
Else
Label1.Text = FindWords(TextBox2.Text, TextBox1.Text)
End If
End If
End Sub
Public Function FindWords(ByVal SearchString As String, ByVal Word As String)
'Integer for number of occurences found
Dim numOccurences As Integer
numOccurences = 0
'Ignore case
'SearchString = SearchString.ToUpper
'Word = Word.ToUpper
'Get rid of commas
SearchString = SearchString.Replace(",", ""

SearchString = SearchString.Replace(".", ""
'Assign array elements to each word in the string
Dim StringArray() As String
StringArray = SearchString.Split(" "
Dim i As Integer
Do Until i = StringArray.Length()
If StringArray(i) = Word Then
numOccurences = numOccurences + 1
End If
i = i + 1
Loop
FindWords = numOccurences
End Function
Function occurrences(ByVal searchString As String, ByVal fullString As String) As Integer
Dim upperSearchString As String = searchString.ToUpper()
Dim upperFullString As String = fullString.ToUpper()
Dim iStart As Integer = 0
Dim iCount As Integer = 0
Dim iStrLen As Integer = upperFullString.Length
Dim iPos As Integer
While iStart <= iStrLen
iPos = upperFullString.IndexOf(upperSearchString, iStart)
If (iPos > -1) Then
iCount = iCount + 1
iStart = iPos + upperSearchString.Length
Else
Exit While
End If
End While
Return iCount
End Function
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
TextBox2.Text = TextBox2.Text.ToUpper()
TextBox1.Text = TextBox1.Text.ToUpper()
End Sub
End Class
[/tt]