Re: regular expressions ?

From: Date: Thu, 27 Jan 2005 19:36:39 +0000
Subject: Re: regular expressions ?
References: 1 2 3 4 5  Groups: php.general 
Request: Send a blank email to php-general+get-207526@lists.php.net to get a copy of this message
Robin Vickery wrote:
On Thu, 27 Jan 2005 16:56:05 +0100, Zouari Fourat <fourat@gmail.com> wrote:
this is working fine : if (eregi("^-?([1-3])+$",$x) echo "x is 1 or 2 or 3";
i forgot to say that doesnt work with 1-20 :( how to do it ?
if (preg_match('/^(20|1[0-9]|1-9])$/', $candidate)) { // $candidate is a decimal integer between 1 and 20 inclusive with no leading zeros. }
/^(1?[1-9]|[12]0)$/ works too. The first part covers 1-9, 11-19; the second part gets you 10 and 20. Plus, it's ever so slightly shorter! And isnt' that what's most important? :P --Rick

« previous php.general (#207526) next »