用python提取身份证年月日
时间: 2023-05-22 07:02:42 浏览: 188
ID-card-with-date-of-birth.rar_birth
可以使用正则表达式来提取身份证的年月日,代码如下:
import re
id_card = "身份证号码"
pattern = r'^(\d{6})(\d{4})(\d{2})(\d{2})(\d{3})([\dX])$'
match = re.match(pattern, id_card)
if match:
year = match.group(2)
month = match.group(3)
day = match.group(4)
print("出生年月日:{}-{}-{}".format(year, month, day))
else:
print("无法提取身份证信息")
阅读全文