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
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments