I have binary pattern "10000101001" and I want to match string having 0 in starting and ending 1. So for above given example there should be 3 possible match 100001, 101, 1001.
Below is the sample code I am trying:
function solution() {
$length = 0;
$decStr = "10000101001";
$pattern = "/[1][^1]0*[1]/";
preg_match_all($pattern, $decStr, $matches);
echo "<pre>";
print_r($matches);
echo "</pre>";
}
This gives output as
Array
(
[0] => Array
(
[0] => 100001
[1] => 1001
)
)