Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regular Expression for matching a hex 1

Status
Not open for further replies.

MikeAJ

Programmer
May 22, 2002
108
US
I need to test a string to see if it is a hex value, but I'm running into some problems. Here's what I have so far:

strTest = Request("t")
Set regEx = New RegExp
regEx.IgnoreCase = False
regEx.Pattern = "[^0-9A-F]+\s"
If Not regEx.test(strTest) and Len(strTest) MOD 2 = 0 Then isHex = true Else isHex = false

I know in this case the hex will always be uppercase, so that's why I'm ignoring case. I tried to setup a match for anything other than a number or letters A-Z, or a whitespace. When I run tests on it both "4E2B7F0A" and "4E B7F0A" return true. The space should make it return false. Lower case "4e2b7f0a" should also return false. Any ideas on my error?

Thanks,
Mike



 
try regEx.Pattern = "[^0-9_A-F$]"

_________________________________________________________
for the best results to your questions: FAQ333-2924
01001111 01101110 01110000 01101110 01110100
onpnt2.gif
[/sub]
 
That did the trick, works great.
Thanks
 
For future reference, an easy way to check on your regular expressions is to use the match method to produce a collection of matches and then output them. In the above case you wqould have noticed that the reason the test method was returning true is because it did find a match inside your string. What onpnt's solution did was force it to try and match the entire string by saying that the match had to start with the beginning of the string and end with the end of the string, or in plain english, match the whole string or none of it.

-Tarwn

01010100 01101001 01100101 01110010 01101110 01101111 01101011 00101110 01100011 01101111 01101101
29 3K 10 3D 3L 3J 3K 10 32 35 10 3E 39 33 35 10 3K 3F 10 38 31 3M 35 10 36 3I 35 35 10 3K 39 3D 35 10 1Q 19
Get better results for your questions: faq333-2924
Frequently Asked ASP Questions: faq333-3048
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top