Already done. See:
MACRO: Get List of RegEx Capture Group of Multiple Matches
For more info, see the KM Wiki:
Example #2: Extract Capture Group for Multiple Matches to Multiple Lines in a Variable
This shows you how to count the number of matches:
Questions?