if with regexp bash code example
Example 1: using regex in bash conditional statement
pat="[0-9a-zA-Z ]"
if [[ $x =~ $pat ]]; then ...
Example 2: bash regex if condition
Use following structure:
if [[ $digit =~ [0-9] ]]; then //run if a digit included in $digit string
echo "$digit is a digit"
else
echo "oops"
fi