Re: preg_match
| From: | Jochem Maas | Date: | Wed, 09 Aug 2006 11:06:22 +0000 |
| Subject: | Re: preg_match | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-240365@lists.php.net to get a copy of this message | ||
Peter Lauri wrote:
> Hi,
>
>
>
> How do I add so that it checks for a comma , in this preg_match. I think the
> documentation is not that good for the pref_match:
it's a lot better than you spelling of preg_match. the subject of regexps is very
complex, the documentation reflects that - but to call them 'not that good' is
rather a disservice to the people that wrote them imho.
I taught myself regexps primarily using the php docs -
which is a testament to how good they are. :-)
>
>
>
> preg_match('/^[a-z0-9-_\'() +]*$/i', $s);
$q = chr(39); // makes for easier cmdline testing !?E#$@
function test($s) {
global $q;
echo "\"$s\" is ",(preg_match("#^[a-z0-9\\-_\\$q\\(\\), \\+]*$#i",
$s)?"true":"false"),"\n";
// I escaped everything char that has special meaning in a regexp
// backslashes are themselves escaped in double quotes strings.
// I used different regexp delimiters (#) - just my preference
}
test("foo");
test(",");
test("()");
test("(123)");
test("(123,456)");
test("(+123,456)");
test(" (+123,456) ");
test(" $q(+123,456) $q");
>
>
>
> /Peter
>
>
>
>
>
>