preg_match_all() 不匹配所有可能出现的情况

preg_match_all() not matching all possible occurrences

我有二进制模式“10000101001”,我想匹配在开始和结束 1 中具有 0 的字符串。因此对于上面给出的示例,应该有 3 个可能的匹配项 100001、101、1001。

下面是我正在尝试的示例代码:

function solution() {
    $length = 0;
    $decStr = "10000101001";
    $pattern = "/[1][^1]0*[1]/";
    preg_match_all($pattern, $decStr, $matches);
    echo "<pre>";
    print_r($matches);
    echo "</pre>";
}

输出为

Array
(
    [0] => Array
        (
            [0] => 100001
            [1] => 1001
        )

)

正面前瞻

/(?=(1[^1]+1))/

读这个:http://www.regular-expressions.info/lookaround.html