#27049 [Opn->Bgs]: Regular Expression Syntax

From: Date: Thu, 29 Jan 2004 02:05:24 +0000
Subject: #27049 [Opn->Bgs]: Regular Expression Syntax
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-54089@lists.php.net to get a copy of this message
ID: 27049 Updated by: sniper@php.net Reported By: al at lufthansa dot com -Status: Open +Status: Bogus Bug Type: *Regular Expressions Operating System: Linux PHP Version: Irrelevant New Comment: Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php .. Previous Comments: ------------------------------------------------------------------------ [2004-01-26 10:58:02] al at lufthansa dot com 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 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=27049&edit=1

« previous php.bugs (#54089) next »