This regular expression check in shell script always false
despite it matches with $LIST
values.
#!/usr/bin/env bash
LIST="AB,CD,EF" # Valid value and should print "VALID!"
if [[ ! "$LIST" =~ ^[A-Z]{2}(?:,[A-Z]{2})*$ ]]
then
echo "INVALID"
else
echo 'VALID!'
fi
For the regex
, some of the invalid $LIST
values would be AB,CD,EF,
, AB,CD,ef
.
What could be the reason for this?