3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string = 'moooozeee'; // The regex matches any character -> . in a capture group () // plus as much identical characters as possible following it -> \1+ $pattern = '/(.)\1+/'; preg_match_all($pattern, $string, $m); // sort by their length usort($m[0], function($a, $b) { return (strlen($a) < strlen($b)) ? 1 : -1; }); echo "Longest sequence: " . $m[0][0] . PHP_EOL;

preferences:
41.43 ms | 402 KiB | 5 Q