FatRat
FatRat

Reputation: 71

Regular expression range 1 25

Hello can someone help me creating a regex for numeric range from 1 to 25, I wouldn't like 01 02 etc just 1 2 3 .... Thanks
My failed attempt /^([1-2]{1,2}[0-9])$/

Upvotes: 1

Views: 202

Answers (1)

xxMrPHDxx
xxMrPHDxx

Reputation: 667

This is the "simple to understand" way

/^([1-9]|1[0-9]|2[0-5])$/

Breakdown:-

  • |: or operator
  • [1-9]: match 1 to 9
  • 1[0-9]: match 10 to 19
  • 2[0-5]: match 20 to 25

Upvotes: 4

Related Questions