DD
DevDash

Regex for Scientific Notation

Regex Pattern

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

Number in scientific notation (e.g. 1.5e10)

Quick Answer

The regex pattern for scientific notation is `^-?\d+(?:\.\d+)?[eE][+-]?\d+$`. Number in scientific notation (e.g. 1.5e10). This works in JavaScript, Python, Ruby, PHP, Java, and most regex engines that support PCRE syntax.

Test Examples

InputResult
1.5e10✓ Matches
-3.14E-5✓ Matches
6.022e23✓ Matches
1E6✓ Matches
1.5✗ No match
1.5f10✗ No match
e10✗ No match
1.5e✗ No match

Code Examples

javascript

const regex = /^-?\d+(?:\.\d+)?[eE][+-]?\d+$/;
const isValid = regex.test(value);

python

import re
pattern = r'^-?\d+(?:\.\d+)?[eE][+-]?\d+$'
if re.match(pattern, value):
    print("valid")

ruby

pattern = /^-?\d+(?:\.\d+)?[eE][+-]?\d+$/
if value =~ pattern
  puts "valid"
end

php

if (preg_match('/^-?\d+(?:\.\d+)?[eE][+-]?\d+$/', $value)) {
    echo "valid";
}

java

String pattern = "^-?\\d+(?:\\.\\d+)?[eE][+-]?\\d+$";
boolean isValid = value.matches(pattern);

Frequently Asked Questions

Related Regex Patterns

Want API access + no ads? Pro coming soon.