|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2004-01-28 21:05 UTC] sniper@php.net
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Nov 03 10:00:02 2025 UTC |
Description: ------------ The escaping the dash character (-) in a characters set of a regular expression is ignored. It works correctly in Perl. Reproduce code: --------------- <? // -*- C -*- echo "<html><body>"; $email = "test-user.lastname\@my-domain.com"; $email = "test-user.lastname+reference\@my-domain.com"; if (eregi( '^[a-z0-9]+[a-z0-9\-\.\+_]*\@([a-z0-9\-\.]+\.[a-z][a-z]+)$', $email)) { echo "Valid"; } else { echo "Invalid"; } echo "</body></html> "; ?> Expected result: ---------------- This should print valid, but prints invalid. I know the work around is to put the -, without the escape, at the end of the regex. Perl works correctly: #! /usr/bin/perl $_ = "test-user.lastname\@my-domain.com"; $_ = "test-user.lastname+reference\@my-domain.com"; if ( /^[a-z0-9]+[a-z0-9\-\.\+_]*\@([a-z0-9\-\.]+\.[a-z][a-z]+)$/) { print "Valid\n"; } else { print "Invalid\n"; } Also see http://bugs.php.net/bug.php?id=10741&edit=2