php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #37600 Strange results with preg_replace using parentheses next to each other
Submitted: 2006-05-26 11:48 UTC Modified: 2006-05-26 11:54 UTC
From: iain at iaindooley dot com Assigned:
Status: Not a bug Package: PCRE related
PHP Version: 5.1.4 OS: FreeBSD 5.4
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: iain at iaindooley dot com
New email:
PHP Version: OS:

 

 [2006-05-26 11:48 UTC] iain at iaindooley dot com
Description:
------------
I can't tell if this is universal, but with this particular regex it certainly is a bug. I think it is to do with using parentheses directly next to each other.

Reproduce code:
---------------
<?
    $str = 'arr[sub][sub_sub]';
    die(preg_replace('/([^\[\]]*)(.*)/','[\1]\2',$str));
?>

just for the record, this works as expected if i use the pattern:

preg_replace('/([^\[\]]*)\[(.*)\]/','[\1][\2]',$el);

so it appears that the problem is when parenthesised (is that correct?) expression appear next to each other.

Expected result:
----------------
[arr][sub][sub_sub]

Actual result:
--------------
[arr][sub][sub_sub][]

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-05-26 11:54 UTC] tony2001@php.net
Please report bugs in PCRELib to PCRE developers (pcre.org).
Thanks.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Jul 14 02:01:32 2025 UTC