3v4l.org

run code in 300+ PHP versions simultaneously
<?php $chat = <<<CHAT <Amanda> Hi there, how are you? <Jack> Hi, im fine <Paul> sup yall <Petra> wasabi <Paul> shall we go for beers? <Petra> most definitely <Jack> see you later CHAT; preg_match_all( '/^<((?!Amanda>|Jack>)[^>]+)> \K.+/m', $chat, $matches, PREG_SET_ORDER ); $result = []; foreach ($matches as [$words, $name]) { $result[$name] = ($result[$name] ?? 0) + str_word_count($words); } var_export($result);

preferences:
24.92 ms | 406 KiB | 5 Q