调整字符串日期的格式

import re


s = 'birthday is 1991-11-19'

res1 = re.sub('(\d{4})-(\d{2})-(\d{2})',r'\2/\3/\1',s)

res2 = re.sub('(?P<year>\d{4})-(?P<month>\d{2})-(?P<day>\d{2})',r'\g<month>/\g<day>/\g<year>',s)

print(res1)
print(res2)

 

posted @ 2019-03-03 15:06  Ray_chen  阅读(386)  评论(0编辑  收藏  举报