3v4l.org

run code in 300+ PHP versions simultaneously
<?php $strings = [ "01", "1001111", "010011111", "0100111110001110", "0100111011001110", "0100111110011110", "0100111111111111110001110", "0100111011001110", "1011010111", "0100111011001110", ]; $pattern = '/^0*\K(?:[01]*?((?(1)\1)1))+/m'; foreach ($strings as $s) { if (preg_match($pattern, $s, $match)) { echo "$s --> " . $match[0] . PHP_EOL; } }

preferences:
31.12 ms | 404 KiB | 5 Q