RE: preg_match problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux