I want to write a regular expression that only allows a user to enter an input which contains alphanumeric characters, underscores, periods, dashes, and plus signs.
In a bash script, I have:
VALID="^[0-9a-zA-Z_\.\-\+]+$"
THE_INPUT=$1
if [[ ! $THE_INPUT =~ $VALID ]]; then
echo "ERROR"
exit 1
fi
Why does this not work when the user enters an input which has a - in it?
Example user inputs:
great-food.png
i. produces error
great_+food.png
i. doesn't produce error