Numbers
Match a floating-point number
Match decimals like 3.14, -0.5, and scientific notation like 1.5e-10.
Pattern
Regular expression
-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?How it works
Optional sign, integer part, optional fractional part, optional exponent. Accepts both plain floats and scientific notation.
Matches
- ▸3.14
- ▸-0.5
- ▸1e10
- ▸1.5e-10
- ▸42
Non-matches
- ▸.5 (no integer part)
- ▸1e (missing exponent)
- ▸abc
Common gotchas
This pattern also matches plain integers like `42`. If you need to exclude them, require a decimal or exponent: `-?\\d+(?:\\.\\d+|[eE][+-]?\\d+)`.
Language snippets
JavaScript
const re = /-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?/g;Python
re.findall(r"-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?", text)Go
re := regexp.MustCompile(`-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?`)Java
Pattern.compile("-?\\d+(?:\\.\\d+)?(?:[eE][+-]?\\d+)?")