- preg_match_all: documentation ( source)
<?php
$str = "Ala ma 2 koty, Adam ma 4 psy";
preg_match_all("/(?P<kto>[A-Z]\w+)\s\w+\s(?P<ile>\d+)/", $str, $matches);
print $matches[0][0] . "\n";
print $matches[0][1] . "\n";
print $matches[1][0] . "\n";
print $matches[1][1] . "\n";