Why <?php preg_match_all('/(?:^|\s)(ABC|XYZ)(?:\s|$)/i', 'ABC XYZ', $match) ?> finds only 'ABC'?
Because the first full match is 'ABC ' - containing the trailing space. And that space is not available for further processing.
Use lookbehind and lookahead to solve this problem: <?php preg_match_all('/(?<=^|\s)(ABC|XYZ)(?=\s|$)/i', 'ABC XYZ', $match) ?>