gpt4 book ai didi

正则表达式检测cuits - Python

转载 作者:行者123 更新时间:2023-12-04 07:57:55 25 4
gpt4 key购买 nike

我需要找到一个正则表达式,让我可以识别以下序列。两个数字间隔 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

最佳答案


(?<!\d)\d{2}\D*\d{8}\D*\d(?!\d)
proof .
说明
--------------------------------------------------------------------------------
(?<! 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-ahead

关于正则表达式检测cuits - Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66607797/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com