Private Function PassesSubstringTest(ByVal myWord As String, ByVal myFragment As String, ByVal matchType As MatchType) As Boolean

 

 

        If myWord = "REDON" Then

            System.Diagnostics.Debug.Print("")

        End If

        '-------------------------------------------------------------------------------

        'anything to do?

        '-------------------------------------------------------------------------------

        If myFragment = "" Then

            '-------------------------------------------------------------------------------

            'no, return "matched:

            '-------------------------------------------------------------------------------

            Return True

        End If

 

        '-------------------------------------------------------------------------------

        'match pattern bigger than word?

        '-------------------------------------------------------------------------------

        If myFragment.Length > myWord.Length Then

            '-------------------------------------------------------------------------------

            'yes, return "not matched:

            '-------------------------------------------------------------------------------

            Return False

        End If

 

        '-------------------------------------------------------------------------------

        'narrow myWord as needed

        '-------------------------------------------------------------------------------

        If matchType = matchType.Last Then

            myWord = Right(myWord, myFragment.Length)

        ElseIf matchType = matchType.First Then

            myWord = Left(myWord, myFragment.Length)

        End If

 

        '-------------------------------------------------------------------------------

        'replace myFragment wild card <.> with regex <[A-Z]>

        '-------------------------------------------------------------------------------

        Dim matchPattern As String = myFragment.Replace(".", "[A-Z]")

        ' Compile the regular expression.

        Dim regex As Regex = New Regex(matchPattern, RegexOptions.IgnoreCase)

        ' Match the regular expression pattern against a text string.

        '-------------------------------------------------------------------------------

        'for non-match,  m.Index = -1, else zero or higher

        '-------------------------------------------------------------------------------

        If Not regex.Match(myWord).Success Then

            Return False

        Else

            Return True

        End If

 

    End Function