<?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; } }
You have javascript disabled. You will not be able to edit any code.