Re: regexp question

From: Date: Fri, 11 Aug 2000 20:25:17 +0000
Subject: Re: regexp question
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-11397@lists.php.net to get a copy of this message
At 2:42 PM -0400 8/11/00, Ryan J Nichols wrote:
can I get a regexp that verifies a string is only 0-9 a-z A-Z or contains _ and - ereg("^[^A-Za-z0-9\d_-]+$",$bah) does not work.
The problem lies in the $" part. PHP does variable substitution in double quotes, so it interprets the $ as the start of a variable name. Use single quotes: ereg('^[^A-Za-z0-9\d_-]+$',$bah) You could also escape the $ if your REALLY want to use double quotes, but in that case you _may_ have to escape the first backslash, too: ereg("^[^A-Za-z0-9\\d_-]+\$",$bah) If I were me, I'd use single quotes, or the regexp Bruce Christensen suggested (it's cleaner, IMHO): ereg('^[[:alnum:]_-]+$')
I've been toying with this for a while with no success, in addition to the answer a nice url to a tutorial on these things would be appreciated. Thanks in advance, Ryan
-steve +--- "They've got a cherry pie there, that'll kill ya" ------------------+
| Steve Edberg                           University of California, Davis |
| sbedberg@ucdavis.edu                               Computer Consultant |
| http://aesric.ucdavis.edu/                  http://pgfsun.ucdavis.edu/ |
+-------------------------------------- FBI Special Agent Dale Cooper ---+

« previous php.general (#11397) next »