|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-08-08 20:08 UTC] 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',
),
)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Dec 05 20:00:01 2025 UTC |
Tried out in javascript too: same result, so I were wrong :-) sorry <body onload="init();"> php:<br /> <?php $p1='/.*/'; $test='some text'; function test($m) { echo '"'.$m[0].'"'; echo '<br />'; return $m[0]; } preg_replace_callback($p1,'test',$test); ?><br /> javascript:<br /> <script> function init() { var p1=<?php echo $p1;?>g; var test="<?php echo $test;?>"; test.replace(p1,function (m) { document.body.appendChild(document.createTextNode('"'+m+'"')); document.body.appendChild(document.createElement('br')); return m; }); } </script> </body>