在第一种情况下,给定日期字符串下面的代码与dmy格式匹配,在第二种情况下,日期字符串与格式不匹配
import re datestring = '21-09-1991' foo =re.match('(\d{2})[/.-](\d{2})[/.-](\d{4})$', datestring) print foo.group() datestring = '1991-09-21' foo =re.match('(\d{2})[/.-](\d{2})[/.-](\d{4})$', datestring) print foo
输出结果
21-09-1991 None