Re: preg match compilation error

From: Date: Mon, 27 Oct 2003 22:56:55 +0000
Subject: Re: preg match compilation error
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-167802@lists.php.net to get a copy of this message
* Thus wrote Luis Lebron (llebron@sigmatech.com): > I found a reqular expresion that I'm using to check for valid characters in > file names. > > Here's the sample code: > > if(preg_match("[^a-zA-Z0-9,._\+\()\-]",$filename)) > { > //blah, blah, blah > } preg_* need a pattern deliminater (most commonly /,#, or !) so it should be: preg_match("/[^a-zA-Z0-9,._\+\()\-]/",$filename) Now you can get rid of all the escapes because mosts characters loose their special meaning inside a character class: preg_match("/[^a-zA-Z0-9,._+()-]/",$filename) You can get away without escaping the '-' because it *can't* be considered a range of characters since it is last (or if its first). That should work. Curt -- "My PHP key is worn out" PHP List stats since 1997: http://zirzow.dyndns.org/html/mlists/

« previous php.general (#167802) next »