Relief:
\d must not be in [] . Use [] only if you want to check if a character is one of several characters or character classes.
. no escaping inside [] - [\.] , just permits . , but including \ in the string instead . may be language dependent (?). Or you can just take it out of [] and save it with shielding.
So we get:
\d{1,16}|\d{1,16}\.\d{1,3}
(which can be shortened using the optional / "once or not at all" quantifier ( ? )
to \d{1,16}(\.\d{1,3})? )
Corrections:
You probably want to make the second \d{1,16} optional or, equivalently, just make it \d{0,16} , so something like .1 possible:
\d{1,16}|\d{0,16}\.\d{1,3}
If something like 1. should also be allowed, you need to add optional . in the first part:
\d{1,16}\.?|\d{0,16}\.\d{1,3}
Edit: I was under the show [\d] , which matches \ or d , but actually matches the \d character class (fixed above).
source share