RegEx: How can I match all numbers greater than 49?

前端 未结 6 779
孤独总比滥情好
孤独总比滥情好 2020-11-29 21:11

I\'m somewhat new to regular expressions and am writing validation for a quantity field where regular expressions need to be used.

How can I match a

6条回答
  •  眼角桃花
    2020-11-29 21:26

    I know there is already a good answer posted, but it won't allow leading zeros. And I don't have enough reputation to leave a comment, so... Here's my solution allowing leading zeros:

    First I match the numbers 50 through 99 (with possible leading zeros):

    0*[5-9]\d
    

    Then match numbers of 100 and above (also with leading zeros):

    0*[1-9]\d{2,}
    

    Add them together with an "or" and wrap it up to match the whole sentence:

    ^0*([1-9]\d{2,}|[5-9]\d)$
    

    That's it!

提交回复
热议问题