I tried the following solution.
if !(($str =~ ^.*[a-zA-Z0-9].*$)); then
continue;
fi
It seems there's something wrong with the syntax.
Both your regex and syntax is incorrect. You need not use regex at all, just need glob for this:
checkStr() {
[[ $1 != *[a-zA-Z0-9]* ]]
}
This will return false if even one alphanumeric is found in the input. Otherwise true is returned.
Test it:
$> if checkStr 'abc'; then
echo "true case"
else
echo "false case"
fi
false case
$> if checkStr '=:() '; then
echo "true case"
else
echo "false case"
fi
true case
$> if checkStr '=:(x) '; then
echo "true case"
else
echo "false case"
fi
false case
!= operator here does that, unless you have a specific set of nonalphanumeric characters in mind.You can use the [:alnum:] character class. I'm negating using the ^:
if [[ "${str}" =~ ^[^[:alnum:]]$ ]] ; then
echo "yes"
fi