locked
REGEX RRS feed

  • Question

  •  

    Please help me find regular expression for wild character match. Say the regex should return true or false depending upon the validated expression.

    USA --> IsMatch("US*") should return true
    USA --> IsMatch("U*") should return true
    USA --> IsMatch("*A") should return true
    USA --> IsMatch("*SA") should return true
    USA --> IsMatch("*A*") should return true
    USA --> IsMatch("A*") should return false

    Regards:
    dipesh

    Thursday, April 20, 2006 3:09 AM

Answers

  • Hi,

    If all you need is to check whether a string match with wildcards, you don't have to use regular expressions, the Like operator should suffice.

    eg.

    "USA" Like "US*"

    return true

    Thursday, April 20, 2006 3:40 AM

All replies

  • Hi,

    If all you need is to check whether a string match with wildcards, you don't have to use regular expressions, the Like operator should suffice.

    eg.

    "USA" Like "US*"

    return true

    Thursday, April 20, 2006 3:40 AM
  • This is fine so long as the string you are comparing does not exceed 359 characters; as I have found in another thread.

    My issue is I want to keep things simple .. and reuse the existing LIKE comparison strings in VB 2003.

    I have used 2005 but there are some issues with multi-threading and getting threads to exit as they do in VB 2003.

     

    Do you have any thoughts on using the same LIKE comparison strings where the source string is greater than 359 characters?

     

    * UPDATE * 7th September 2007

     

    Regular Expressions [http://www.regular-expressions.info/] is VERY useful for regular expressions.

    It was here I found the solution to this .. use

     

    .*

     

    notation for everything .. and if you want to break things down, use ..

     

    .*US.*

     

    I include some sample code which will get you started, unless you have already found the answer:

     

    Dim blnDoesMatch As Boolean = False

    Dim regexPattern As System.Text.RegularExpressions.Regex

    Dim regexpatternMatch As System.Text.RegularExpressions.Match

    Dim strPatternMatch As System.String = "ABC_USA_DEF"

    Dim strKey As System.String = ".*US.*"

     

    regexPattern = New System.Text.RegularExpressions.Regex(strKey)

    regexpatternMatch = regexPattern.Match(strPatternMatch)

    blnDoesMatch = regexpatternMatch.Success

     

    I Hope this helps you and anyone else accessing this Thread.

     

    Cheers,

     

    MrPlatypus

    Monday, September 18, 2006 9:51 AM