Python正则表达式抽取身份证号

输入为一段文本,输出为字符串,多个身份证号中间空格符隔开

def person_id_extract(text):
    person_id = re.findall(
        r"([1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx])", text)
    per_id = ""
    if person_id:
        matrix = numpy.array(person_id)
        for i in matrix[:, 0]:
            per_id = per_id + ' ' + "".join(tuple(i))
    return per_id

 

你可能感兴趣的:(python,正则表达式,python,nlp,numpy)