how to match a number which is less than or equal to 100?

前端 未结 7 1464
耶瑟儿~
耶瑟儿~ 2020-12-03 04:35

I want to match a number which is less than or equal to 100, it can be anything within 0-100, but the regex should not match for a number which is greater than 100 like 120,

7条回答
  •  失恋的感觉
    2020-12-03 05:17

    My practical Advice.

    Personally, I would refrain writing such a complex regex altogether. What if your number changes from 100 to 200 in near future. Your regex will have to change significantly and it might be even harder to write. All the above solutions are NOT self explanatory and you will have to complement it with a comment in your code. That's a smell.

    Readability matters. Code is for humans and not for machines.

    Why not write some code around it and keep regex dead simple to understand.

提交回复
热议问题