import re with_tab = "--- tab.py\t2009-12-27\n" with_space = "+++ space.py 2009-12-28\n" for line in (with_tab, with_space): match = re.match("\S{3}\s" "(?P\w?\:?(?:[\/\\]?[\w\.])*)\s+" "(?P.*)", line) print("{0} - {1}".format(match.group("file"), match.group("date")))