php.net |  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
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: axelm-php at nona dot net
New email:
PHP Version: OS:

 

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

Example: 

- 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.



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-08-24 12:04 UTC] jani@php.net
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-2022 The PHP Group
All rights reserved.
Last updated: Wed May 25 10:03:33 2022 UTC