Should match any valid JavaScript number/bigint literal.
See 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 (except with leading 0
s).
(decimal point)0
s
.
or scientific notation will error)0b
binary
.
or scientific notation0o
octal
.
or scientific notation0x
hexadecimal
.
or scientific notationn
0
s except after a 0o
/0x
/0b
prefix+
, .
, or scientific notationNote, Number()
(parsing from a string) allows leading/trailing whitespace and scientific notation, but not _
, and leading 0
s are not an implicit octal prefix, (and ofc no BigInt suffix)