正则表达式用于逗号分隔值的倍数为100且最高为1000

时间:2014-01-04 10:43:04

标签: regex

任何正文都可以帮我解决一个正则表达式,该正则表达式验证逗号分隔值的倍数为100且最多为1000。

例如100,200,1000 例如100,1000,100

此致 PK

2 个答案:

答案 0 :(得分:4)

试试这个:

^(?:10|[1-9])00(?:,\s*(?:10|[1-9])00)*$

<强>解释

The regular expression:

(?-imsx:^(?:10|[1-9])00(?:,\s*(?:10|[1-9])00)*$)

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
----------------------------------------------------------------------
  (?:                      group, but do not capture:
----------------------------------------------------------------------
    10                       '10'
----------------------------------------------------------------------
   |                        OR
----------------------------------------------------------------------
    [1-9]                    any character of: '1' to '9'
----------------------------------------------------------------------
  )                        end of grouping
----------------------------------------------------------------------
  00                       '00'
----------------------------------------------------------------------
  (?:                      group, but do not capture (0 or more times
                           (matching the most amount possible)):
----------------------------------------------------------------------
    ,                        ','
----------------------------------------------------------------------
    \s*                      whitespace (\n, \r, \t, \f, and " ") (0
                             or more times (matching the most amount
                             possible))
----------------------------------------------------------------------
    (?:                      group, but do not capture:
----------------------------------------------------------------------
      10                       '10'
----------------------------------------------------------------------
     |                        OR
----------------------------------------------------------------------
      [1-9]                    any character of: '1' to '9'
----------------------------------------------------------------------
    )                        end of grouping
----------------------------------------------------------------------
    00                       '00'
----------------------------------------------------------------------
  )*                       end of grouping
----------------------------------------------------------------------
  $                        before an optional \n, and the end of the
                           string
----------------------------------------------------------------------
)                        end of grouping
----------------------------------------------------------------------

答案 1 :(得分:0)

^(?:1000,?|[1-9]00,?)+$

<强> Live demo