Regular Expressions 101

Community Patterns

Number or Range

2

Regular Expression
ECMAScript (JavaScript)

/
^\s*(\d+(?:\.\d+)?)(?:\s*\-\s*(\d+(?:\.\d+)?))?\s*$
/
g

Description

Allows either a number (e.g. "1", "1.01") or a range (e.g. "1-2", "1.0 - 1.3"). Also allows whitespace on either side of the numbers.

Submitted by Mark Newcomb - 8 years ago