当前位置: 动力学知识库 > 问答 > 编程问答 >

regex - regular expression ten numbers but not ten zero

问题描述:

This question already has an answer here:

  • regex: creating an exception for r:a.?b.?c

    2 answers

网友答案:

How about this:

^(?!0{10})\d{10}$

Explanation:

The regular expression:

(?-imsx:^(?!0{10})\d{10}$)

matches as follows:

NODE                     EXPLANATION
----------------------------------------------------------------------
(?-imsx:                 group, but do not capture (case-sensitive)
                         (with ^ and $ matching normally) (with . not
                         matching \n) (matching whitespace and #
                         normally):
----------------------------------------------------------------------
  ^                        the beginning of the string
----------------------------------------------------------------------
  (?!                      look ahead to see if there is not:
----------------------------------------------------------------------
    0{10}                    '0' (10 times)
----------------------------------------------------------------------
  )                        end of look-ahead
----------------------------------------------------------------------
  \d{10}                   digits (0-9) (10 times)
----------------------------------------------------------------------
  $                        before an optional \n, and the end of the
                           string
----------------------------------------------------------------------
)                        end of grouping
----------------------------------------------------------------------
分享给朋友:
您可能感兴趣的文章:
随机阅读: