Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get 1-100 using regex

Tags:

regex

I'm trying to get something like:

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

I've made something like this so far:

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

But it can't get 132 and 100. How can I fix this?

like image 299
Adam Ramadhan Avatar asked Jun 19 '11 06:06

Adam Ramadhan


2 Answers

Try this regex which matches a number of 1 or 2 digits, or 100:

\d{1,2}(?!\d)|100
like image 165
Benoit Avatar answered Oct 30 '22 20:10

Benoit


Why not keeping 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 won't match prepended zeros e.g. "Hello, 00001". It can be easily extended, though:

^[a-zA-Z]{1,255}, 0*(100|[1-9][0-9]?)$
like image 41
CAFxX Avatar answered Oct 30 '22 22:10

CAFxX