Help Help - 4 months ago 6
PHP Question

Regular Expression (PHP) => greater that or if not

It is possible to have in a regular expression (php), something like '>' or 'if not' ¿?

For example: I have a 5 number string 'XXXXX': '00054', '47690', '20593'...

I need a regular expression that verify:


  1. 5 numbers

  2. Greater that 1



I had this: '/^[0-9]{5}$/' but doesn't verify the greater than '00001' !

I'm looking for something like '>' or 'if not 00000'...

Thanks

PS: I know that can be done with: if((int)$string > 1)

Answer

I can figure out 2 ways:

/^(?!00000)\d{5}$/

This first checks that the start is not followed by 5 zeros, then searches for 5 digits.

/^(?:[1-9]\d{4}|\d[1-9]\d{3}|\d{2}[1-9]\d{2}|\d{3}[1-9]\d|\d{4}[1-9])$/

This one checks for 5 combinations, each of which contains a non-zero digit in one of the 5 positions.