<?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);