Geeks With Blogs
Rodney Vinyard - .NET & SQL Developer When all is said and done, more will be said than done

    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

Posted on Wednesday, March 14, 2007 10:27 AM regex - regular expressions | Back to top


Comments on this post: fiinding a substring like "ON" (or with wildcard <.> like ".N" in a bigger string like "YONDER"

# re: fiinding a substring like "ON" (or with wildcard <.> like ".N" in a bigger string like "YONDER"
Requesting Gravatar...
Am I missing something? Besides being a wrapper around the Regex class what does your function do? If anything it's a little confusing becuase it changes the semantics of .Net's Regular Expression implementation. The ".", can mean any character including new line given the right regex options. You are changing it to mean a Capital A-Z set, with ignore case option. Why not just pass that argument directly to the Regex static function IsMatch?
Left by dave on Mar 14, 2007 1:29 PM

# re: fiinding a substring like "ON" (or with wildcard <.> like ".N" in a bigger string like "YONDER"
Requesting Gravatar...
The subject that you accentuate in your essay excites me greatly since recently. I mean it. You've hit the mark! Good job and I like your style too.
Left by Thesis Writing on Jun 24, 2010 2:49 PM

# re: fiinding a substring like "ON" (or with wildcard <.> like ".N" in a bigger string like "YONDER"
Requesting Gravatar...
what should i say about this blog its so wonderful
Left by cost effective seo company on Oct 04, 2011 12:02 PM

# re: fiinding a substring like "ON" (or with wildcard <.> like ".N" in a bigger string like "YONDER"
Requesting Gravatar...
Thanks for sharing this info. Please keep porting about this matter It is very interesting. Ocio
Left by Ocio on Nov 14, 2011 1:47 PM

# re: fiinding a substring like "ON" (or with wildcard <.> like ".N" in a bigger string like "YONDER"
Requesting Gravatar...
Thank you for the good writeup. It in fact was a amusement account it. Look advanced to far added agreeable from you! By the way,<a href=” http://www.monsterbeats-studio.com/”>monster beats how could we communicate?
Left by Monster beats on Nov 14, 2011 7:55 PM

Your comment:
 (will show your gravatar)


Copyright © Rodney Vinyard | Powered by: GeeksWithBlogs.net