logic behind time regex matching