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

Pull Requests

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-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 03 17:01:26 2024 UTC