php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52723 Something wrong with preg_replace
Submitted: 2010-08-28 16:22 UTC Modified: 2010-08-28 16:37 UTC
From: clark21330 at gmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.2.14 OS: Win Server 2008
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: clark21330 at gmail dot com
New email:
PHP Version: OS:

 

 [2010-08-28 16:22 UTC] clark21330 at gmail dot com
Description:
------------
you see,I just need one 1 in the return value,but,where did the second "1" come from?

I use ([a-zA-Z0-9])* to match all numbers and letters, and I just using only one "a" as the input parameter

But how can the return value be the "double 1"?

Test script:
---------------
echo preg_replace("/([a-zA-Z0-9])*/","1","a");

Expected result:
----------------
11


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-08-28 16:37 UTC] rasmus@php.net
-Status: Open +Status: Bogus
 [2010-08-28 16:37 UTC] rasmus@php.net
* doesn't mean what you think it does in a regular expression.  You want a + 
there.  Like this:

echo preg_replace("/([a-zA-Z0-9])+/","1","a");
 [2010-08-29 02:55 UTC] clark21330 at gmail dot com
I will try it~Thanks rasmus~
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 02 15:01:34 2025 UTC