Regular Expression for 3 digit without 000

风流意气都作罢 提交于 2019-12-06 07:43:35

Use alternations:

[1-9][A-Z]{2}([1-9][0-9][0-9]|[0-9][1-9][0-9]|[0-9][0-9][1-9])

See regex demo

Here,

  • [1-9] - matches 1 digit from 1 to 9
  • [A-Z]{2} - two uppercase ASCII letters
  • ([1-9][0-9][0-9]|[0-9][1-9][0-9]|[0-9][0-9][1-9]) - 3 alternatives:
    • [1-9][0-9][0-9] - 3-digit numbers starting with 1
    • [0-9][1-9][0-9] - 3-digit numbers having 1 in the middle
    • [0-9][0-9][1-9] - 3-digit numbers ending with 1

Also, see this regex demo.

Use a negative look-ahead to avoid the triple zero at the end:

[1-9][A-Z]{2}(?!000)[0-9]{3}

Using the alternation operator [1-9][1-9][1-9]|0[1-9][1-9]|00[1-9]|0[1-9]0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!