From: al at lufthansa dot com
Operating system: Linux
PHP version: Irrelevant
PHP Bug Type: *Regular Expressions
Bug description: Regular Expression Syntax
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 = "[EMAIL PROTECTED]";
$email = "[EMAIL PROTECTED]";
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
$_ = "[EMAIL PROTECTED]";
$_ = "[EMAIL PROTECTED]";
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 bug report at http://bugs.php.net/?id=27049&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=27049&r=trysnapshot4
Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=27049&r=trysnapshot5
Fixed in CVS: http://bugs.php.net/fix.php?id=27049&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=27049&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=27049&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=27049&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=27049&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=27049&r=support
Expected behavior: http://bugs.php.net/fix.php?id=27049&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=27049&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=27049&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=27049&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=27049&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=27049&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=27049&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=27049&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=27049&r=float