﹎斑斓的梦ぷ

愿你眼中总有光芒,活成你想要的模样.

导航

Python - 验证日期格式

import re
print re.search(r'\d{4}-\d{2}-\d{2}', 'xxxx1990-12-20xxxx').group(0)
print re.search(r'\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}', 'xxxx2005-06-04T18:37:11xxxx').group(0)
print re.search(r'\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}', 'xxxx2005-06-04T18:37:11.111xxxx').group(0)
 
pattern=re.compile(r'(\d{4}-\d{2}-\d{2})((T\d{2}:\d{2}:\d{2}|))((.\d{3})|)')
print pattern.search('xxxx2005-06-04T18:37:11.111xxxx').group(0)

posted on 2018-05-25 11:17  ﹎斑斓的梦ぷ  阅读(2657)  评论(0编辑  收藏  举报