Numbersflags: g
Float / Scientific Number
Match floating-point and scientific-notation numbers including `1.5`, `.25`, `1e10`, `-3.14E-2`.
Try it in RegexPro →Available in
JavaScript / ECMAScript code
jsJavaScript
const re = new RegExp("[-+]?(?:\\d+\\.?\\d*|\\.\\d+)(?:[eE][-+]?\\d+)?", "g");
const input = "h = 6.626e-34, c = 3e8, alpha = .007";
const matches = [...input.matchAll(re)];
console.log(matches.map(m => m[0]));Uses `String.prototype.matchAll` for global iteration (Node 12+ / all modern browsers).
Python (re) code
pyPython
import re
pattern = re.compile(r"[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?")
input_text = "h = 6.626e-34, c = 3e8, alpha = .007"
for m in pattern.finditer(input_text):
print(m.group(0))Stdlib `re` module — no third-party dependency. Works on Python 3.6+.
Go (RE2) code
goGo
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?`)
input := `h = 6.626e-34, c = 3e8, alpha = .007`
for _, match := range re.FindAllString(input, -1) {
fmt.Println(match)
}
}Uses `regexp.MustCompile` (panics on bad patterns at startup) and `FindAllString` for all matches.
Pattern
regexengine-agnostic
[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)? (flags: g)Raw source: [-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?
How it works
[-+]? matches an optional sign. (?:\d+\.?\d*|\.\d+) matches the mantissa as either digits-with-optional-decimal or decimal-with-trailing-digits. (?:[eE][-+]?\d+)? matches the optional exponent. Covers most real-number literals you'll encounter in source or data.
Examples
Input
h = 6.626e-34, c = 3e8, alpha = .007Matches
6.626e-343e8.007
Input
Range -1.5 to +2.5Matches
-1.5+2.5
Input
no numbers hereNo match
—Common use cases
- •Scientific-notation parsing in CSV/log data
- •Source-code analysis (constants extraction)
- •Lexer tooling for math DSLs
- •Data validation in physics / finance pipelines
Related patterns
Scientific Notation
NumbersMatches numbers in scientific/exponential notation (e.g., 1.5e10).
Decimal Number
NumbersMatches decimal numbers, including integers and negatives.
Binary Number Literal
NumbersMatch binary number literals like `0b1010` or `0B11110000`.
Hexadecimal Number Literal
NumbersMatch hexadecimal number literals like `0xFF`, `0x1A2B`, or `0XdeadBeef`.