Numbers

Scientific Notation

Matches numbers in scientific/exponential notation (e.g., 1.5e10).

Try it in RegexPro →

Available in

JavaScript / ECMAScript code

jsJavaScript
const re = new RegExp("^-?\\d+(\\.\\d+)?[eE][+-]?\\d+$", "");
const input = "1.5e10";
const match = input.match(re);
console.log(match ? match[0] : null);

Uses `String.prototype.match`, which returns the first match or null.

Pattern

regexengine-agnostic
^-?\d+(\.\d+)?[eE][+-]?\d+$

Raw source: ^-?\d+(\.\d+)?[eE][+-]?\d+$

How it works

`^-?\d+(\.\d+)?` matches a signed decimal. `[eE]` allows either exponent marker. `[+-]?\d+$` matches the signed exponent digits.

Examples

Input

1.5e10

Matches

  • 1.5e10

Input

-2.7E-5

Matches

  • -2.7E-5

Input

3.14

No match

—

Common use cases

  • •Scientific computing
  • •Data import
  • •Numeric parsing

Related patterns