我需要找到一个正则表达式,它允许我识别以下序列。两个数字空间,8个数字空间,一个数字空间。数字之间可以出现多个字符组合。
\d{2}.?\d{8}.?\d{1}应匹配:
11 11111111 1
11-11111111-1
11.11111111.1
11|11111111|1
11.11111111 1
11 11111111 1不应该匹配:
11 11111111 11
1 11111111 11发布于 2021-03-12 22:05:12
使用
(?<!\d)\d{2}\D*\d{8}\D*\d(?!\d)见证明。
解释
--------------------------------------------------------------------------------
(?<! look behind to see if there is not:
--------------------------------------------------------------------------------
\d digits (0-9)
--------------------------------------------------------------------------------
) end of look-behind
--------------------------------------------------------------------------------
\d{2} digits (0-9) (2 times)
--------------------------------------------------------------------------------
\D* non-digits (all but 0-9) (0 or more times
(matching the most amount possible))
--------------------------------------------------------------------------------
\d{8} digits (0-9) (8 times)
--------------------------------------------------------------------------------
\D* non-digits (all but 0-9) (0 or more times
(matching the most amount possible))
--------------------------------------------------------------------------------
\d digits (0-9)
--------------------------------------------------------------------------------
(?! look ahead to see if there is not:
--------------------------------------------------------------------------------
\d digits (0-9)
--------------------------------------------------------------------------------
) end of look-aheadhttps://stackoverflow.com/questions/66607797
复制相似问题