正则表达式的范围> = 0但小于1000

Jon*_*han 5 regex

我正在忙着做这件事,以为我会把它放在那里.

它必须是一个最多3个单位且最多5个小数位的数字等

有效

  • 999.99999
  • 99.9
  • 9
  • 0.99999
  • 0

无效

  • -0.1
  • 999.123456
  • AAA
  • AAA.99999

编辑它需要大于或等于零.

oha*_*aal 13

根据您最近对问题的更改,这里是一个更新的正则表达式,它将匹配所有> = 0和<1000

^\d{1,3}(?:\.\d{1,5})?$
  ^\___/ \/ ^\/\___/ |
  |  ^   ^  | |  |   `- Previous is optional (group of dot and minimum 1 number between 0-9 and optionally 4 extra numbers between 0-9)
  |  |   |  | |  `- Match 1-5 instances of previous (single number 0-9)
  |  |   |  | `- Match a single number 0-9
  |  |   |  `- The dot between the 1-3 first number(s) and the 1-5 last number(s).
  |  |   `- This round bracket should not create a backreference
  |  `- Match 1-3 instances of previous (single number 0-9)
  `- Match a single number 0-9
Run Code Online (Sandbox Code Playgroud)

^是行的开始,$是行尾.

有效

  • 999.99999
  • 999.0
  • 999
  • 99.9
  • 99.0
  • 99
  • 9
  • 0.1
  • 0.01
  • 0.001
  • 0.0001
  • 0.99999
  • 0.01234
  • 0.00123
  • 0.00012
  • 0.00001
  • 0.0
  • 0.00000
  • 0
  • 000.00000
  • 000

无效

  • -0.1
  • 999.123456
  • AAA
  • AAA.99999
  • 0.
  • 0.123