|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42411 clarification why not using PCRE.
Submitted: 2007-08-24 11:54 UTC Modified: 2007-08-24 12:16 UTC
From: axelm-php at nona dot net Assigned:
Status: Not a bug Package: Regexps related
PHP Version: 5.2.3 OS: Debian/GNU Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
40 + 19 = ?
Subscribe to this entry?

 [2007-08-24 11:54 UTC] axelm-php at nona dot net
The function ereg_replace() "duplicates" the replacement string when the match string is ".*".


- input "BLABLA"
- match ".*"
- replace "TEST"

Output is "TESTTEST", although it would be expected to be "TEST".

Reproduce code:

$source = "BLABLA";
$match = ".*";
$replace = "TEST";

print ereg_replace($match, $replace, $source);
print "\n";


Expected result:
only a single "TEST" (as this is the case with sed, too), because i expect ".*" to have maximum greediness.

Actual result:
see example code. produces "TESTTEST". This happens in all PHP versions i have access to (older PHP4, current PHP4 and PHP5).

Using "^.*" as match, or ".+" works as expected.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2007-08-24 12:04 UTC]
Expected behaviour. And you should really use PCRE functions instead.
 [2007-08-24 12:16 UTC] axelm-php at nona dot net
Hm.. other regex implementations don't repeat the text. Well, i don't have any interest in breaking a fight here..

With regards to PCRE - there are applications which don't allow the use of the additional Perl functionality, but require plain POSIX regex. The application i use it for is ENUM (RFC3761).

Thanks anyway for looking at this.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Feb 25 10:01:26 2024 UTC