|
-
Jul 27th, 2006, 04:12 AM
#1
Thread Starter
Addicted Member
[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:
Dim strIMEIFormat as String = "\d{6}-\d{2}-\d{6}-\d{1}"
Dim strIMEI as String = "123456-12-123456-1"
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]
-
Jul 27th, 2006, 11:57 AM
#2
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:
Dim strIMEIFormat As String = "^\d{6}-\d{2}-\d{6}-\d{1}$"
Dim strIMEI As String = "123456-12-123456-1"
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|