Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use regex to match a number between 1 and 105

Tags:

regex

I've tried several options without success.

(105)|(0*\d{1,2})

This is where I go?

like image 289
IRONLORD Avatar asked Dec 14 '25 23:12

IRONLORD


1 Answers

I like the answer above /10[0-5]|[0-9]{1,2}/ but it is not anchored so it will match things like 990 and 1051. It will match as a regexp I mean.

To anchor the regexp use ^ at the start and $ at the end. Here's an improved version of the answer

/^(10[0-5]|\d{1,2})$/

I've used \d which is a commonly available shortcut for [0-9] digits

Edit: see tripleee's comment below, also needs ( ) to group the two alternate expressions

like image 134
Vorsprung Avatar answered Dec 16 '25 21:12

Vorsprung



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!