Results 1 to 2 of 2

Thread: [02/03] Regex Problem

  1. #1

    Thread Starter
    Addicted Member hyousuf2's Avatar
    Join Date
    Dec 2004
    Location
    Dublin
    Posts
    226

    [02/03] Regex Problem

    Im trying to use Regex.IsMatch method to match an IMEI number with the input data. but its not working properly. sometimes even if the data is correct, it would return false and vice versa also. here's da code

    VB Code:
    1. Dim strIMEIFormat as String = "\d{6}-\d{2}-\d{6}-\d{1}"
    2. Dim strIMEI as String = "123456-12-123456-1"
    3. MsgboxBox(Regex.IsMatch(strIMEI,strIMEIFormat)

    Am i missing something or what ?
    Women ...r like tea bags, you neva know how strong they really r untill u put them in hot water

    Huzefa Yousuf
    Software Engineer
    Verticity Inc.
    +92-345-2235303

    [email protected]

  2. #2
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: [02/03] Regex Problem

    Works fine for me, for a slight modification, you can add a beginning "^" and an ending "$" to the pattern if your string is supposed to contain the whole match and nothing else, that would tell it to match on the entire string, and if the entire string doesnt match, then it should return false. Below is a modified example of the pattern I am talking about, although both worked fine for me.
    VB Code:
    1. Dim strIMEIFormat As String = "^\d{6}-\d{2}-\d{6}-\d{1}$"
    2.         Dim strIMEI As String = "123456-12-123456-1"
    3.         MessageBox.Show(System.Text.RegularExpressions.Regex.IsMatch(strIMEI, strIMEIFormat).ToString)
    Does your string you are wanting to match on always contain just a pattern you are wanting to match? Or other things as well? If this number can be anywhere inside of a long string of text, then you don't want the beginning and end characters that I added.

    One last thing... when you are testing this and saying that sometimes it returns false, are you sure that the string you are giving it should return true?

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