Regular Expressions 101

Community Patterns

Floating Point number verifier and extractor with scientific notation support

1

Regular Expression
PCRE (PHP <7.3)

/
^(([+-]?(?:\d*(?:\.(?=\d))?\d*))(?:(?:(?<=\d)[Ee])?((?2)))(?<=\d))?$
/
g

Description

The regex verifies floating point numbers in decimal or scientific notation with extensive error checking - however, there may be edge cases which i haven't addressed, so feel free to put in more unit tests!

Submitted by Tamoghna Chowdhury - 7 years ago