Regular Expressions 101

Community Patterns

Community Library Entry

2

Regular Expression
PCRE2 (PHP >=7.3)

/
\b(?<!-)(?:\d{1,2}|100)\b
/
gmi

Description

Could you help me validate my input and only match positive integers between the range of 0 and 100?

There can be several numbers in a string which I would want to retrieve.

Try out these example strings:

Sam has 200 apples. He gives Todd 20 and Mary 125. The weather is -5 C today, but will be +5 C tomorrow.

Submitted by anonymous - 2 days ago