首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用于检测cuits - Python的Regex

用于检测cuits - Python的Regex
EN

Stack Overflow用户
提问于 2021-03-12 22:02:57
回答 1查看 29关注 0票数 2

我需要找到一个正则表达式,它允许我识别以下序列。两个数字空间,8个数字空间,一个数字空间。数字之间可以出现多个字符组合。

代码语言:javascript
复制
\d{2}.?\d{8}.?\d{1}

应匹配:

代码语言:javascript
复制
11 11111111 1
11-11111111-1
11.11111111.1
11|11111111|1
11.11111111  1
11  11111111  1

不应该匹配:

代码语言:javascript
复制
11  11111111  11
1  11111111  11
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-03-12 22:05:12

使用

代码语言:javascript
复制
(?<!\d)\d{2}\D*\d{8}\D*\d(?!\d)

证明

解释

代码语言:javascript
复制
--------------------------------------------------------------------------------
  (?<!                     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
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66607797

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档