Python (re)

Scientific Notation in PY

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

Try it in the PY tester →

Pattern

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

Python (re) code

pyPython
import re

pattern = re.compile(r"^-?\d+(\.\d+)?[eE][+-]?\d+$")
input_text = "1.5e10"
for m in pattern.finditer(input_text):
    print(m.group(0))

Stdlib `re` module — no third-party dependency. Works on Python 3.6+.

How the pattern 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

Same pattern, other engines

← Back to Scientific Notation overview (all engines)