3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string = 'moooopuuuooze'; // 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 // sort by their length usort($m[0], 'length_sort'); function length_sort($a, $b) { return (strlen($a) < strlen($b)) ? 1 : -1; } echo "Longest sequence: " . $m[0][0] . "\n";

preferences:
43.94 ms | 402 KiB | 5 Q