php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27049 Regular Expression Syntax
Submitted: 2004-01-26 10:58 UTC Modified: 2004-01-28 21:05 UTC
Votes:1
Avg. Score:2.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: al at lufthansa dot com Assigned:
Status: Not a bug Package: *Regular Expressions
PHP Version: Irrelevant OS: Linux
Private report: No CVE-ID: None
 [2004-01-26 10:58 UTC] 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


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-01-28 21:05 UTC] sniper@php.net
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

..

 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Thu Feb 21 10:01:25 2019 UTC