Scientific Notation Regex
Validates a number written in scientific (exponential) notation, such as 1.23e-10 or -6.022E23, with a mantissa, an e/E marker, and a signed integer exponent.
Regex Pattern
^-?\d+(\.\d+)?[eE][+-]?\d+$Pattern Breakdown
Hover over a token to see what it does.
| Token | Meaning |
|---|---|
| ^ | Anchors the match to the start of the string. |
| -? | An optional leading minus sign for a negative mantissa. |
| \d+ | One or more digits for the integer part of the mantissa. |
| (\.\d+)? | An optional fractional part of the mantissa, a dot followed by one or more digits. |
| [eE] | The literal exponent marker, lowercase e or uppercase E. |
| [+-]? | An optional sign on the exponent, defaulting to positive when omitted. |
| \d+ | One or more digits for the exponent value. |
| $ | Anchors the match to the end of the string. |
Detailed Explanation
What it does
This pattern matches numbers written in scientific notation: a mantissa (an integer or decimal number, optionally negative) followed by an e or E marker and a signed or unsigned integer exponent. Examples include 1e10, 1.23e-10, and -6.022E23. Plain numbers without an exponent marker are rejected.
Why it works
The mantissa is built the same way as a general number, with a required integer portion and an optional `(\.\d+)?` fractional portion, so both whole-number and decimal mantissas are supported. The `[eE]` class accepts either letter case used for the exponent marker, and `[+-]?\d+` requires at least one exponent digit while allowing an explicit sign. Anchoring both ends ensures the exponent marker isn't optional or missing, which is what distinguishes this from a plain decimal number.
Common use cases
- Validating numeric literals in a data file or scientific dataset that uses exponential notation
- Parsing measurement values from instruments or APIs that report very large or very small magnitudes
- Pre-checking user input in a scientific or engineering calculator application
- Detecting scientific notation in text before converting it with a numeric parser
Edge cases
- 1e10 matches even without a fractional mantissa or explicit exponent sign, since both are optional
- 1.5E+10 matches with an uppercase marker and an explicit positive exponent sign
- 1e (a marker with no exponent digits) correctly fails since at least one exponent digit is required
- 10 (no exponent marker at all) correctly fails, distinguishing it from a plain decimal number
Limitations
- Does not accept a fractional exponent, since real-world exponential notation always uses an integer exponent
- Does not validate that the resulting numeric value fits within a particular floating-point precision or range
- Does not accept alternative notations like 1x10^10 that some non-programming contexts use for scientific notation
Interactive Tester
Edit the pattern or text below — matching runs live in your browser.
Test Cases
Editable — add your own inputs to see if they pass.
| Input | Expected | Result | |
|---|---|---|---|
| Pass | |||
| Pass | |||
| Pass | |||
| Pass | |||
| Pass | |||
| Pass | |||
| Pass | |||
| Pass |
Language Variants
Production-ready examples in 12 languages.
const scientificPattern = /^-?\d+(\.\d+)?[eE][+-]?\d+$/;
function isScientificNotation(value) {
return scientificPattern.test(value);
}
console.log(isScientificNotation("1.23e-10")); // trueCommon Mistakes
Making the exponent digits optional, which would let a bare 'e' with no digits incorrectly match.
Fix: Keep `\d+` (one or more) for the exponent, not `\d*`, so at least one exponent digit is required.
Forgetting that a mantissa without a fractional part, like 1e10, is perfectly valid scientific notation.
Fix: Keep the fractional mantissa group optional with `(\.\d+)?` rather than requiring it.
Only matching lowercase 'e', missing values that use an uppercase 'E' marker.
Fix: Use the character class `[eE]` to accept either case.
Performance Notes
- All groups use bounded, non-overlapping quantifiers, so the pattern matches in linear time with no catastrophic backtracking.
- Anchoring both ends lets malformed input, like a missing exponent marker, fail immediately.
- The optional fractional-mantissa group is checked before the mandatory exponent, so integer-mantissa values like 1e10 skip that branch quickly.
Browser Compatibility
| Engine | Supported | Notes |
|---|---|---|
| Chrome | Yes | — |
| Firefox | Yes | — |
| Safari | Yes | — |
| Edge | Yes | — |
| Node.js | Yes | — |