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
| Input | Result |
|---|---|
| 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
Positive Integer
Integers greater than zero (no leading zeros)
Non-negative Integer
Zero or positive integer
Decimal Number
Optionally signed decimal number
Hex Color Code
3 or 6-digit hex color with optional #
USD Currency
US dollar amount with optional $ and thousands separators
Hex Color with Alpha
Hex color code with optional alpha channel (3, 4, 6, or 8 digits)