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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reg ex

Status
Not open for further replies.

Stunner01225

Technical User
Mar 13, 2002
150
GB
Hello.
I am writing a piece of server side code that uses Regular expressions (groan). I have been trying to get it right for days now.
I receive Input in the form of strings formatted as such "0.0" , "0.0.0" ,"0.0.0.0"
I need an expression that will be true for the first("0.0") but not any others. the expression also has to pass "10.0" as true.
I have been working along the lines of \d+\.\d+ but I cannot get it to work.
Does anyone have any ideas?

Thanks in advance for any help given.
 
I wish I could download it, but security is too high on my workstation. I will try to get hold of it but in the meantime im afraid I will need some more suggestions as I only have vis studio 2k3 in front of me at the moment.
 
I Think all my expressions are passing 0.0.0 as true becuase it finds 0.0 in it once. Anybody know how to fix it I need an exact match and my RegEx are not my greatest.
 
^(\d*[0])(\.[0]{1})$
first group zero or more digits and a zero must follow
second group .0 only

what I have tested
Enter string: 0.0
good string 0.0
Enter string: 00.0
good string 00.0
Enter string: 10.0
good string 10.0
Enter string: 0
bad string 0
Enter string: 0.0.0
bad string 0.0.0
Enter string: 0.0.0
bad string 0.0.0.0
Enter string: 1.0
bad string 1.0
Enter string: 0
bad string 0

If 00.0 is not allowed change to this
^([1-9]*[0])(\.[0]{1})$

Marty
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top