3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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";
based on uigai
Output for 4.3.0 - 7.2.0
Longest sequence: oooo