Re: Regular expression help?

From: Date: Mon, 02 Feb 2004 22:04:18 +0000
Subject: Re: Regular expression help?
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-176628@lists.php.net to get a copy of this message
Jas wrote:
Adam Bregenzer wrote:
On Mon, 2004-02-02 at 14:15, Jas wrote:
I have tried this but its not working.
             !eregi("^[0-9a-fA-F]{2}\:[0-9a-fA-F]{2}\:[0-9a-fA-F]{2}\:[0-9a-fA-F]{2}\:[0-9a-fA-F]{2}\:[0-9a-fA-F]{2}$",$_POST['mac']) 
so it should match 2 characters 0-9a-fA-F each block of 2 characters is followed by a : and repreated in 6 blocks.
That's a long expression, try: !preg_match('/^([0-9a-f]{2}($|:)){6}/i', $_POST['mac']); This pattern finds 6 matches of a number or letter (the /i means case-insensitive) followed by either a ':' or the end of the string.
Thanks, that worked like a charm. Jas
You may want to check out The Regex Coach. It's very helpful. :-) http://www.weitz.de/regex-coach/ -- paperCrane <Justin Patrin>

« previous php.general (#176628) next »