How to get 1-100 using regex

I am trying to get something like:

Hello, 0 ( dont get ) Hello2, 100 ( get ) hello3, 82 ( get ) hello< 132 ( dont get ) 

I have done something like this so far:

 [a-zA-Z]{1,255},([0-9]{1,3})(?<![0]) 

But he cannot get 132 and 100 . How can i fix this?

+6
source share
3 answers

Try this regular expression that matches the number of 1 or 2 digits, or 100:

 \d{1,2}(?!\d)|100 
+16
source

Why not keep it simple?

 ^[a-zA-Z]{1,255}, (100|[1-9][0-9]|[1-9])$ 

or better yet

 ^[a-zA-Z]{1,255}, (100|[1-9][0-9]?)$ 

Note: this will not match previous zeros, for example. "Hello, 00001." It can be easily expanded, but:

 ^[a-zA-Z]{1,255}, 0*(100|[1-9][0-9]?)$ 
+4
source

Try it. It will match from 1 to 99 or 100. A number greater than 100 will be invalid.

 (?:\b|-)([0-9]{1,2}|100)\b 

Link to the script .. https://regex101.com/r/mN1iT5/462

+1
source

Source: https://habr.com/ru/post/890848/


All Articles