PHP preg_match_all匹配数组print_r的解释


Explanation for PHP preg_match_all matches array print_r

我对preg_match_all的用法如下:

$re = "/^(-''w+''s*.*)''n*$/um"; 
$str = "-Give on result'n-Second new text'n-The third text'n'nAnother paragraph without list.'n'n-New list here"; 
preg_match_all($re, $str, $matches);

print_r($matches)的输出有一个奇怪的数组:

Array
(
    [0] => Array
        (
            [0] => -Give on result
            [1] => -Second new text
            [2] => -The third text
            [3] => -New list here
        )
    [1] => Array
        (
            [0] => -Give on result
            [1] => -Second new text
            [2] => -The third text
            [3] => -New list here
        )
)

这里我说的是索引0的数组,print_r()输出中出现了目视空白行。的确,这个问题可能与我的另一个问题关于regex和我需要知道为什么这两个数组是不同的?这里有一个在线演示

试着简单地制作

<?php
//$re = "/^(-''w+''s*.*)''n*$/um"; 
$re = "/^(''h*(?:-|&)''h*'w+''s*.*)''n*$/um";
$str = "-Give on result'n-Second new text'n-The third text'n'nAnother paragraph without list.'n'n-New list here"; 
preg_match_all($re, $str, $matches);
echo "<pre>";
print_r($matches);
echo "</pre>";
$i = 0;

    echo "<ul>".preg_replace_callback($re,function($mt){return "<li>".$mt[1]."</li>";},$str)."</ul>";

$re = array_filter(preg_split('/'n/', $str));
echo "<pre>";
print_r($re);
echo "</pre>";

我想复制这个。我通常使用这个工具https://www.debuggex.com/r/AXpFXcR-ioMLhLCd,它以一种更花哨的方式解释Regex条件。

到目前为止,我认为代码评估正则表达式,只有一个'n被捕获,所以下一个直接传递到输出。但是我正在尝试确认这种行为