在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/Java  Python/ 怎么寫一條正則去匹配15位、18位、還有最后一個(gè)字符為字母的身份證號(hào)

怎么寫一條正則去匹配15位、18位、還有最后一個(gè)字符為字母的身份證號(hào)

大佬們,我想用一條正則表達(dá)式在一堆字符串里面去匹配匹配15位、18位、還有最后一個(gè)字符為字母的身份證號(hào)。那一堆字符串如下:

|_ Potentially risky methods: TRACE
|_http-server-header: /2.4.23 (Win32) OpenSSL/1.0.2j PHP/5.4.45
|_http-title: 403 Forbidden
88/tcp filtered kerberos-sec
135/tcp filtered msrpc
139/tcp filtered netbios-ssn
389/tcp filtered ldap
440923195906209416445/tcp filtered microsoft-ds
Device type: general purpose|media device|router|specialized|WAP440923195906207971
Running (JUST GUESSING): Microsoft Windows 2003|XP|2000 (92%), Microsoft embedde
d (88%), Linksys embedded (87%), AVtech embedded (85%), Apple embedded (85%)
OS CPE: cpe:/o:microsoft:windows_server_2003::sp1 cpe:/o:microsoft:windows_serve
r_2003::sp2 cpe:/o:micr440923195906206717osoft:windows_xp::sp3 cpe::airport_extreme cpe:/o
:microsoft:windows_2000::sp4:server
Aggressive OS guesses: Microsoft Windows Server 2003 SP1 or SP2 (92%), Microsoft
Window 44092319590620907xs XP SP3 or
irmware 3.1) (88%), Linksys BEFSR41 EtherFast router (87%), Microsoft Windows Se
rver 2003 SP2 (87%), AVtech Room Alert 26W environmental monitor (85%), Microsof
t Windows XP SP2 or SP3 (85%), Apple AirPort Extreme WAP (85%), Microsoft Window
s 2000 Server SP4 or Windows XP Professional SP3 (85%), Microsoft Windows 2000 S
P4 (85%)
No exact OS matches for host (test conditions non-ideal).
Network Distance: 15 hops
Service Info: OS: Windows; CPE: cpe:/o:microsoft:windows

已知有一條可以匹配18位的正則:
[1-9]d{5}(?:19|20)dd(?:0[1-9]|1[012])(?:0[1-9]|[12]d|3[01])d{4}
會(huì)匹配到一下身份證:
440923195906209416
440923195906207971
440923195906206717
但是不會(huì)匹配到
44092319590620907x

求各位大佬指點(diǎn)一下怎么改一下這條正則表達(dá)式!謝謝!

PS:以上身份證號(hào)都是隨機(jī)生成的身份證號(hào),并非真實(shí)身份證號(hào),請(qǐng)熟知。

PS:我想用python去實(shí)現(xiàn)···

回答
編輯回答
葬憶

/^(^[1-9]d{7}((0d)|(1[0-2]))(([0|1|2]d)|3[0-1])d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/

2018年5月8日 16:20
編輯回答
她愚我

18位

(?:1[1-5]|2[1-3]|3[1-7]|4[1-6]|5[0-4]|6[1-5])\d{4}(?:1[89]|20)\d{2}(?:0[1-9]|1[0-2])(?:0[1-9]|[12]\d|3[01])\d{3}(?:\d|[xX])

15位

(?:1[1-5]|2[1-3]|3[1-7]|4[1-6]|5[0-4]|6[1-5])\d{4}\d{2}(?:0[1-9]|1[0-2])(?:0[1-9]|[12]\d|3[01])\d{3}
2017年4月14日 04:57
編輯回答
孤島

介紹

xxxxxx yyyy MM dd 375 0 十八位

xxxxxx yy MM dd 75 0 十五位

地區(qū): [1-9]d{5}

年的前兩位: (18|19|([23]d)) 1800-2399

年的后兩位: d{2}

月份: ((0[1-9])|(10|11|12))

天數(shù): ((0-2)|10|20|30|31) 閏年不能禁止29+

三位順序碼: d{3}

兩位順序碼: d{2}

校驗(yàn)碼: [0-9Xx]

正則表達(dá)式

十八位: ^[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]$

十五位: ^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{2}$

總:

( ^[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]$)|(^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{2}$)

2018年1月25日 19:26
編輯回答
冷溫柔

你可以試試這個(gè),我在我本地試了是好用的

<input type="text" id="inputVal" >
<div id="test">測(cè)試</div>
let test= document.getElementById("test");
test.addEventListener("click", function () {
   let input = document.getElementById("inputVal").value;
   let reg = /(^\d{15}$)|(^\d{17}([0-9]|X)$)/;
   if (!reg.test(input)) {
     alert("你的身份證號(hào)碼格式不對(duì)!");
   } else {
     alert("OK!");
   }
});    
2017年9月5日 03:05
編輯回答
瘋浪

根據(jù)身份證編碼格式可以試試這個(gè):
18位:

(?<n1>[1,6][1-5]|2[1-3]|3[1-7]|4[1-6]|5[0-4]|71|8[1-2])\d{4}(?<n1>19|20)\d{2}(?<n3>0[1,3,5,7,8](0[1-9]|[1,2]\d|3[0,1])|02(0[1-9]|[1-2]\d)|0[4,6,9](0[1-9]|[1,2]\d|30)|1[0,2](0[1-9]|[1,2]\d|3[0,1])|11(0[1-9]|[1,2]\d|30))\d{3}(?<n4>\d|[x,X])

15位:

(?<n1>[1,6][1-5]|2[1-3]|3[1-7]|4[1-6]|5[0-4]|71|8[1-2])\d{6}(?<n3>0[1,3,5,7,8](0[1-9]|[1,2]\d|3[0,1])|02(0[1-9]|[1-2]\d)|0[4,6,9](0[1-9]|[1,2]\d|30)|1[0,2](0[1-9]|[1,2]\d|3[0,1])|11(0[1-9]|[1,2]\d|30))\d{3}
2017年4月15日 15:12
編輯回答
莫小染
/^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])(\d{3}[Xx])$)$/

身份證最后一位應(yīng)該只有X吧

正常的身份證匹配為:/^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/

2018年8月5日 20:38