Results 1 to 2 of 2

Thread: Regex Help matching

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Location
    Toledo, OH
    Posts
    785

    Regex Help matching

    I have a few sentences that contain a set of words. The regex pattern must match two words in order to be true. But I have a combination of 3 words to be matched that are case insensitive.

    The following expression does a great job... but not quite. I wish to shorten the expression by getting rid of the last group and instead having the first group validate the last group. (I have the last group to match any you or your after the hum.)

    Code:
    (\b[yY]ou(r)?\b.*){1,2}(\bhum(ming)?\b(\byour?\b.*)?)
    Here are the sentences it needs to match within.

    Code:
    Your continue to hum your song.
    
    You continue to fumble slightly as you hum a confident lullaby.
    
    You finish humming a confident lullaby.
    
    You continue to hum a confident lullaby with only the slightest hint of dofficulty.
    If the pattern above matches.. I need it to then grab the areas where it didn't match and ONLY those areas.
    RATE THOSE WHO ARE HELPFUL PLEASE!!

  2. #2
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: Regex Help matching

    Like this?
    Code:
    Dim pattern = "\b(your?)\b(.*)\b(hum(?:ming)?)\b(.*)"
    Dim rx As New Regex(pattern, RegexOptions.IgnoreCase)
    
    Dim phrases = New String() { _
    "Your continue to hum your song.", _
    "You continue to fumble slightly as you hum a confident lullaby.", _
    "You finish humming a confident lullaby.", _
    "You continue to hum a confident lullaby with only the slightest hint of dofficulty."}
    
    For Each phrase In phrases
        Dim m = rx.Match(phrase)
        Debug.WriteLine(m.Groups(1).Value)
        Debug.WriteLine(m.Groups(2).Value)
        Debug.WriteLine(m.Groups(3).Value)
        Debug.WriteLine(m.Groups(4).Value)
        Debug.WriteLine("")
    Next
    That is the very essence of human beings and our very unique capability to perform complex reasoning and actually use our perception to further our understanding of things. We like to solve problems. -Kleinma

    Does your code in post #46 look like my code in #45? No, it doesn't. Therefore, wrong is how it looks. - jmcilhinney

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width