Re: preg_match problem

From: Date: Tue, 23 Jan 2007 12:52:17 +0000
Subject: Re: preg_match problem
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-247626@lists.php.net to get a copy of this message
2007/1/22, Beauford <phpuser@netscan.ca>:
... much blah blah blah ... I've probably read 100 pages on this, and no matter what I try it doesn't work. Including all of what you suggested above - is my PHP possessed? if(preg_match("/^[A-Za-z0-9!@#$%&()*;:_.'/\\ ]+$/", $string)) { gives me this error. Warning: preg_match() [function.preg-match]: Unknown modifier '\' in /constants.php on line 107 So if If you wouldn't mind, could you show me exactly what I need right from the beginning and explain why it works. i.e. if(preg_match(what goes here", $string)) { Echo "You got it";
if (preg_match('/^[A-Za-z0-9!@#$%&()*;:_.'\\/\\\\ ]+$/', $string)) Use single quotes and double back-slashes. PHP strings also have escape sequences that use the back-slash as escape character, that's why you have to double them. And single quotes to avoid the $ character interpreted as the start of a variable. PS: Will we be risking going the perl way if we ask that PHP supported regular expressions natively (I mean: without having to provide them as strings)?

« previous php.general (#247626) next »