Regular Expressions 101

Community Patterns

Any number between 0 and 10 with 0 or 1 decimal places

2

Regular Expression
PCRE (PHP <7.3)

/
(?<![\d\.-])\d(\.\d)?(?!(\.\d)|\d)|(?<![\d\.-])10(?!(\.\d)|\d])
/
g

Description

Matches any number between 0 and 10 (inclusive) with 0 or 1 decimal places. Note that .5 will NOT be matched but 0.5 will. Also 10.X will not be matched, but 10 will.

Submitted by Matt Coubrough - 9 years ago