如果是1个固定的内容,代码应该是可以的,但是要求是用text所有内容,请问如何实现呢?或者前后哪里有错吗?谢谢!
import re
import datetime
text='''
1. abc 2016-10-31
2. xyz 2016-9-4
3. aef 2016-10-aa
4. asasf asdf 10-14
5. 2013-10-3 234234
6. 1945-8-15 abc 1945
7. 1972-01-30 asdf 1988-10-1
'''
a = re.findall(r'\d{4}-\d{1,2}-\d{1,2}',text)
b = ",".join(a)
c = datetime.datetime.strptime(b,'%Y-%m-%d').strftime('%m/%d/%Y')
print(a.index(i)+1,end='. ')
print(c)