I have this code with regular expression:
read string
regex="^[1-9][0-9]*\+[1-9][0-9]+$"
if [[ "$string" =~ $regex ]]; then
echo "it's ok"
fi
Regular expression works for me, but when I insert a string with initial space , for example " 9+2", it should not recognize it(because in the regex I say it that the string must start with a number and not a space) but it print "it's ok" although it should not.
Why? what wrong in this code?