I have tested the regex here: http://regexr.com/3bchs
I cant get the array to only print the regex search terms.
files=(`ls $BACKUPDIR`)
daterange='(2015\-06\-)[0-9]+\s?'
for i in "${files[@]}"
do
if [[ "$files[$i]" =~ $daterange ]];
then
echo $i
fi
done
Input: 2015-06-06 2015-06-13 2015-06-20 2015-06-27 2015-07-04 2015-07-11
Output:
2015-06-06
2015-06-13
2015-06-20
2015-06-27
2015-07-04
2015-07-11
bash -vx <script>to see how the values are evaluated. This might shed some lights on what goes wrong.{}in$files[$i]. Try${files[$i]}