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);
Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
array ( 'Paul' => 7, 'Petra' => 3, )

preferences:
82.06 ms | 406 KiB | 5 Q