Bash get regex number up to 2 digits

I just need to know how to create a regular expression that takes a number containing up to two digits

All i have now

^[0-9]{2}$ 

Which will correspond to a number with exactly 2 digits, but I don’t know how to indicate "match a number that has up to two digits".

In addition, if there is a way to make sure that this number is not equal to 0, this will be a plus, otherwise I can check it with Bash.

Thanks!:)

Note that the input variable comes from read -p "makes a choice" Number

EDIT MY POST EXHIBITION CODE IN THE CONTEXT:

 while true; do read -p "Please key in the number of the engineer of your choice, or leave empty to select them all: " Engineer if [ -z "$Engineer" ]; then echo "No particular user specified, all engineers will be selected." UserIdSqlString="Transactions.Creator!=0 " break else if [[ $Engineer =~ ^[0-9]{1,2}$ && $Engineer -ne 0 ]]; then echo "If you want a specific engineer type their number otherwise leave blank" else echo "yes" break fi fi done 
+6
source share
3 answers

bash [[ conditional expression supports extended regular expressions.

 [[ $number =~ ^[0-9]{,2}$ && $number -ne 0 ]] 

or as the unique @gniourf_gniourf points out in his comments, you need to correctly handle numbers with leading zeros

 [[ $number =~ ^[0-9]{,2}$ ]] && ((number=10#$number)) 
+6
source
 ^([1-9]|[1-9]{1}[0-9]{1})$ 

corresponds to each number from 1,2,3 ... 99

+5
source

-_- searched for it for 20 minutes and immediately found the answer right after I posted it ... ^ [0-9] {1,2} $

+3
source

Source: https://habr.com/ru/post/957693/


All Articles