RE: [PHP] preg_match problem

From: Date: Tue, 23 Jan 2007 19:22:13 +0000
Subject: RE: [PHP] preg_match problem
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-247639@lists.php.net to get a copy of this message
At 1/23/2007 09:50 AM, Beauford wrote:
         preg_match("/^[A-Za-z0-9!@#$%&()*;:_.'\/\\\\ ]+$/", $string)
On top of this, every time a ' is entered it gets preceded by \. If I just check for the characters like below that doesn't happen. Totally confused. if(preg_match("/^[-A-Za-z0-9_.' ]+$/", $string)) {
You don't need to escape the apostrophe if the pattern isn't quoted with apostrophes in PHP or delimited by apostrophes in the PREG pattern. But generally there's no harm in escaping characters unnecessarily; it just makes for messier code. Here is a simple test of the regexp I recommended yesterday using the pattern:
        "/^[A-Za-z0-9!@#$%&()*;:_.'\/\\\\ ]+$/"
http://juniperwebcraft.com/test/regexp_test_2007-01-23.php If you're still having trouble getting this to work, please post a link to a page that demonstrates it not working and give us the complete PHP statements so we can find your error. As an additional resource, here's Oliver Steele's RegExp workbench: http://osteele.com/tools/rework/ Regards, Paul __________________________ Juniper Webcraft Ltd. http://juniperwebcraft.com

« previous php.general (#247639) next »