ID:               49198
 User updated by:  inf3rno dot hu at gmail dot com
 Reported By:      inf3rno dot hu at gmail dot com
 Status:           Bogus
 Bug Type:         PCRE related
 Operating System: *
 PHP Version:      5.2.10
 New Comment:

I don't agree. How do you explain the same behaviour with the .*$
pattern? 
I think .* have to return a single string not two, it's simple logic.
One match for one string.


Previous Comments:
------------------------------------------------------------------------

[2009-08-09 11:55:26] ras...@php.net

I am also pretty sure that this isn't actually a bug.  Doing a
match_all on a non-anchored pattern containing .* is going to match an
empty string.  Remember that * means 0 or more instances of the previous
term.  So, you are doing a match_all for 0 or more characters, and when
you do this non-anchored you are going to get an empty string matching
that.  Change it to .+ (+ means 1 or more) and your patterns start to
make sense and as you will see, the output is what you expect.

------------------------------------------------------------------------

[2009-08-09 11:11:23] ras...@php.net

If you change:
preg_match_all($p,$t,$m,PREG_SET_ORDER);
to:
preg_match($p,$t,$m);

There is no empty match.  I get this output:

/.*/<br /><div style="color: green;">ok</div><pre>array (
  0 => 'some text',
)</pre><br /><br />/.*$/<br /><div style="color:
green;">ok</div><pre>array (
  0 => 'some text',
)</pre><br /><br />/^.*/<br /><div style="color:
green;">ok</div><pre>array (
  0 => 'some text',
)</pre><br /><br />/^.*$/<br /><div style="color:
green;">ok</div><pre>array (
  0 => 'some text',
)</pre><br /><br />

If you can get this effect with preg_match(), please show how.

------------------------------------------------------------------------

[2009-08-09 10:49:19] inf3rno dot hu at gmail dot com

It's not preg_match_all specific, same bug with every preg function.

------------------------------------------------------------------------

[2009-08-08 21:04:32] paj...@php.net

Not windows specific

------------------------------------------------------------------------

[2009-08-08 20:08:15] inf3rno dot hu at gmail dot com

Description:
------------
For pattern: .* there is an empty match at the end of the string.

Reproduce code:
---------------
$p1='/.*/';
$p2='/.*$/';
$p3='/^.*/';
$p4='/^.*$/';
$test='some text';

function test($p,$t)
{
        preg_match_all($p,$t,$m,PREG_SET_ORDER);
        echo $p.'<br />';
        if (count($m)==1)
                echo '<div style="color: green;">ok</div>';
        else
                echo '<div style="color: red;">bug</div>';
        echo '<pre>'.var_export($m,true).'</pre>';
        echo '<br /><br />';
}

test($p1,$test);
test($p2,$test);
test($p3,$test);
test($p4,$test);

Expected result:
----------------
I'm expecting one match in the preg_match_all result array, and I will
get two instead of one. The second match is empty.

Actual result:
--------------
/.*/
bug

array (
  0 => 
  array (
    0 => 'some text',
  ),
  1 => 
  array (
    0 => '',
  ),
)



/.*$/
bug

array (
  0 => 
  array (
    0 => 'some text',
  ),
  1 => 
  array (
    0 => '',
  ),
)



/^.*/
ok

array (
  0 => 
  array (
    0 => 'some text',
  ),
)



/^.*$/
ok

array (
  0 => 
  array (
    0 => 'some text',
  ),
)


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=49198&edit=1

Reply via email to