Regex to match 2 digits, optional decimal, two digits


I've spent half an hour trying to get this, maybe someone can come up with it quickly.

I need a regular expression that will match one or two digits, followed by an optional decmial point, followed by one or two digits.

For example, it should match these strings in their entirety:







and NOT match anything with more than 2 digits before or after the decmial point.

Best Solution

EDIT: Changed to fit other feedback.

I understood you to mean that if there is no decimal point, then there shouldn't be two more digits. So this should be it:


That should do the trick in most implementations. If not, you can use:


And that should work on every implementation I've seen.