php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39947 preg_replace failed to replace contiguous char
Submitted: 2006-12-25 18:11 UTC Modified: 2006-12-25 18:46 UTC
From: dlanoire at neuf dot fr Assigned:
Status: Not a bug Package: PCRE related
PHP Version: 5.2.0 OS: Windows XP SP2
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: dlanoire at neuf dot fr
New email:
PHP Version: OS:

 

 [2006-12-25 18:11 UTC] dlanoire at neuf dot fr
Description:
------------
When I try replace the dot by "_d_", preg_replace fails to replace all dots separated by only 1 character. Only One substitution by 2 is working.

Reproduce code:
---------------
$texte = preg_replace("/(\w)\.(\w)/", "$1_d_$2", "a.b.c.d.e.f");


Expected result:
----------------
The result is a_d_b.c_d_d.e_d_f

Actual result:
--------------
The result should be a_d_b_d_c_d_d_d_e_d_f

On the other side, the replacement below works and gives the good result : aa_d_bb_d_cc_d_dd_d_ee_d_ff

$texte = preg_replace("/(\w)\.(\w)/", "$1_d_$2", "aa.bb.cc.dd.ee.ff");

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-12-25 18:46 UTC] tony2001@php.net
I get the very same result using Perl script, which means it's a PCRE library bug/feature and it should be reported to PCRE developers.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jan 15 10:01:29 2025 UTC