Re: regexp question

From: Date: Fri, 11 Aug 2000 20:34:01 +0000
Subject: Re: regexp question
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-11402@lists.php.net to get a copy of this message
Hi, That's not the problem -- '$' as the last character before the end-quote is interpreted correctly. The problem is the '^', which means not, and the '-', which must be the first element in the set: ereg("^[A-Za-z0-9_-]+$",$bah) Ciao, Andreas Steve Edberg wrote: > > 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 ---+ > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#11402) next »