Should match any valid JavaScript number literal incl. bigint.
See EDIT 4
in this StackOverflow answer by me for matching JS numbers.
open in regex101 editor - example matches and unit tests
Regulex - colored graph
Regexper - slightly smaller and less colored graph
+
/-
Infinity
and NaN
_
as numerical separator between any two digits.
(decimal point)0
s
0b
binary
.
or scientific notation0o
octal
0
and when all digits (before any .
) are below 8.
or scientific notation0x
hexadecimal
.
or scientific notation
E
in scientific notation will be part of the hexadecimal numbern
0
s except after a 0o
/0x
/0b
prefix+
, .
, or scientific notationNote, Number()
(parsing from a string) allows leading/trailing whitespace, but not _
, and leading 0
s are not an implicit octal prefix, (and ofc no BigInt suffix)