|  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
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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: al at lufthansa dot com
New email:
PHP Version: OS:


 [2004-01-26 10:58 UTC] al at lufthansa dot com
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\";
$email = "test-user.lastname+reference\";

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\";
$_ = "test-user.lastname+reference\";

if ( /^[a-z0-9]+[a-z0-9\-\.\+_]*\@([a-z0-9\-\.]+\.[a-z][a-z]+)$/) {
  print "Valid\n";
} else {
  print "Invalid\n";

Also see


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-01-28 21:05 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at


PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed May 22 01:01:31 2024 UTC