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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Mon May 06 18:01:35 2024 UTC