I need a regex expression that will match the following:
.5
0.5
1.5
1234
but NOT
0.5.5
absnd (any letter character or space
Here's a much simpler solution that doesn't use any look-aheads or look-behinds:
^\d*\.?\d+$
To clearly understand why this works, read it from right to left:
7 works
77 works
.77 works
0.77 works
0. doesn't work
.77 works
77 works
..77 doesn't work
.77 works
0.77 works
0077.77 works
0077 worksNot using look-aheads and look-behinds has the added benefit of not having to worry about RegEx-based DOS attacks.
HTH