Regex to match 2 digits, optional decimal, two digits

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:

\d{0,2}(\.\d{1,2})?

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

[0-9]?[0-9]?(\.[0-9][0-9]?)?

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

Leave a Comment