我有二进制模式“10000101001”,我想匹配开始和结束为 1 的字符串。因此对于上面给出的示例,应该有 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
)
)
最佳答案
关于php - preg_match_all() 不匹配所有可能出现的情况,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34506267/