I'm working on a regex formula that will check if the supplied file for processing has either of the following formats:
- SN1234_filename.pdf
- SN1234_filename.pdf.zip
This is what I have right now:
MYFILE="SN39586_invoice.pdf"
ISZIP=0
if [ $ISZIP -eq 0 ]; then
FORMAT='^SN[0-9]+\_[a-zA-Z0-9]+\\.pdf$'
else
FORMAT='^SN[0-9]+\_[a-zA-Z0-9]+\\.pdf\\.zip$'
fi
if [[ $MYFILE =~ $FORMAT ]]; then
# Do some processing
else
echo "invalid file format"
fi
This is working currently, but I want to get rid of the if-else block that sets the FORMAT variable. How can I optimize the FORMAT variable?