I wouldn't bother looking for the end-of-string in the pattern.
Most succinctly, capture the first occurring character then allow zero or more repetitions of the captured character, then restart the fullstring match with \K
so that no characters are lost in the explosions.
Code: (Demo)
var_export(
preg_split('~(.)\1*\K~', '10001101', 0, PREG_SPLIT_NO_EMPTY)
);
Output:
array (
0 => '1',
1 => '000',
2 => '11',
3 => '0',
4 => '1',
)
If you don't care for regular expressions, here is a way of iterating through each character, comparing it to the previous one and conditionally concatenating repeated characters to a reference variable.
Code: (Demo) ...same result as first snippet
$array = [];
$lastChar = null;
foreach (str_split('10001101') as $char) {
if ($char !== $lastChar) {
unset($ref);
$array[] = &$ref;
$ref = $char;
$lastChar = $char;
} else {
$ref .= $char;
}
}
var_export($array);