python獲取手機短信驗證碼 Python怎么用正則表達式匹配全省身份證號前六位?
Python怎么用正則表達式匹配全省身份證號前六位?Import re module:Import reidcardpattern=R“44D{15}(D | x)”,例如廣東省的身份證以44開頭,S
Python怎么用正則表達式匹配全省身份證號前六位?
Import re module:
Import reidcardpattern=R“44D{15}(D | x)”,例如廣東省的身份證以44開頭,STR1=“4405821988110812180x”,要比較的字符串m=重新編譯(idcardpattern)。Match(STR1)print(“Match:”str(m.group())
上面的例子通過了python3的測試,可以匹配18位數(shù)字。只需找到前六位數(shù)字并將其更改為:idcardpattern=R“44D{4}”。