I'm trying to match a string such as: "+99", "-82", "5", "auto" and "max", == auto and max and numbers (let them say integers) with or without a sign
I tried regex
var='^([+|-]{0,1}[0-9][0-9]*)|(auto)|(max)$'
but it fails "at least n times, but no more than m", in my case {0,1} In any case, I tested var = 'ab {0,1}' and var = 'ab {2} 'and they don't work either
I did not succeed, but I realized that the following problem could be like this :()
I am using #! / Bin / bash version 4.2.24 (1)
Thanks in advance!
edit1:
I don't know how to group this regex for ? to work, as suggested by Cara Horvath. I am using this check function that I found somewhere.
#!/bin/bash
INTEGER_MAX='^([+-])?[0-9][0-9]*$'
function isNumeric() {
check=`echo $1 | sed "s/\($2\)//"`
if [ -z ${check} ]; then
return 0
else
return 1
fi
}
isNumeric "$1" "$INTEGER_MAX" && echo "passed"
edit2 - SOLVED
he works with
RE='(^([+-])?[0-9]+$)|(^auto$)|(^max$)'
checked for
[[ $string =~ $pattern ]] && echo "passed"
thank!
source
share