Set mtime with part of filename

Needed to go through a directory of backuped files and set the mtime. The files had the format x-yymmdd.sql.gz A recent copying of the directory had removed the original mtime attributes (note to self: use rsync with -a flag next time).

This one liner did the trick of converting them back to what they had:

for f in *.sql.gz; do touch -d $(echo $f | \
sed "s/^\w\+-\([0-9]\{2\}\)\([0-9]\{2\}\)
\([0-9]\{2\}\).*/20\1-\2-\3/") $f; done

Could this be improved? Most certainly. I havent figured out how to do repetitions in a good manner in regex