Regular Expressions 101

Community Patterns

Floating point and scientific notation regex

0

Regular Expression
PCRE2 (PHP >=7.3)

/
^ (?: [+-]? # optional sign (?: # start a conditional group \d+ # either a nonzero number of digits | # or a decimal phrase \d* # optional digits preceding the decimal \.(?=\d) # a literal decimal followed by at least one digit \d* # optionally some more digits ) # note this group is mandatory! (?: # start an optional scientific notation group [eE] # the scientific notation character [+-]? # optional sign \d+ # after sci notation, you cannot go directly to a decimal )? ) $
/
gmx

Description

Matches real/FP numbers which may optionally also include a scientific notation/exponent part.

Submitted by Kevin Winner - a year ago