php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45479 wrong result when using preg_replace with /u and ungreedy *?
Submitted: 2008-07-10 16:53 UTC Modified: 2008-07-15 10:13 UTC
From: michael dot virnstein at brodos dot de Assigned:
Status: Closed Package: PCRE related
PHP Version: 5.2.6 OS: 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:
MUST BE VALID
Solve the problem:
30 - 7 = ?
Subscribe to this entry?

 
 [2008-07-10 16:53 UTC] michael dot virnstein at brodos dot de
Description:
------------
When i use preg_replace with the /u utf-8 modifier and an ungreedy search e.g. with *?, the result is different to a call without /u.

Reproduce code:
---------------
<?php
echo "without /u:". preg_replace('/^[^d]*?(d)?$/', '\\1', 'abc');
echo "<br>";
echo "with /u: ".preg_replace('/^[^d]*?(d)?$/u', '\\1', 'abc');
?>

Expected result:
----------------
without /u:
with /u:

Actual result:
--------------
without /u:
with /u: abc

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-07-15 10:13 UTC] nlopess@php.net
Bug was in PCRE (http://bugs.exim.org/show_bug.cgi?id=732) and not in PHP. Anyway the fix will be bundled with the next PCRE release.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Sun Sep 20 17:01:25 2020 UTC