Regular Expressions 101

Community Patterns

Community Library Entry

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 - 8 years ago