通过以下代码段,可以比较好学习正则表达式!
import re
l=['350624198308100100','350624192605200011','350624199907311000','350624200012150888']
for i in l:
match=re.search(r'(350624)((19)|(20))\d{2}([0][1-9]|(10|11|12))([0][1-9]|[1-2][0-9]|(30|31))\d{4}',i)
#(r'(350624)([19|20]/d{2})([0][1-9]|[11-12])([0][1-9]|[1-2][0-9]|[30-31])',i)
if match:
print(match.group(0))
运行结果:
C:\Python36-32\python.exe D:/untitled/pq1.py
350624198308100100
350624192605200011
350624199907311000
350624200012150888
Process finished with exit code 0