我想要一个特定的值,这个值只能是数字且:
长度应为11。
第一位数字应为0。
第二位数字应为1。
第三位数字应为0、1、2或5。
然后匹配从第四位到结尾的任何数字。
如果第三位数字是1,则最后两位数字(第10位和第11位)应相同。
如果第三位数字是2,则第8位和第9位数字应相同。
输入字符串,并期望得到结果。
01012345678 -----> allowed.
0101234a5678 -----> not allowed., letter exists.
01112345688 -----> allowed, 10th, 11st are the same
01112345677 -----> allowed, 10th, 11st are the same
01112345666 -----> allowed, 10th, 11st are the same
01112345689 -----> not allowed..10th, 11st different
01112345-678 -----> not allowed..hyphen exists.
01298765532 -----> allowed..8th, 9th are the same.
01298765732 -----> not allowed, 8th, 9th different.
01298765mm432 -----> not allowed, letter exists.
01500011122 -----> allowed..
020132156456136 -----> not allowed..more than 11 digit.
01530126453333 -----> not allowed..more than 11 digit.
00123456789 -----> not allowed.. second digit not 1.
这是我尝试使用regex101的结果,
^01[0125][0-9]{8}$
https://regex101.com/r/cIcD0R/1
,但它忽略了特定情况,同时也适用于特定情况。