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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Fri May 03 07:01:32 2024 UTC