I have an emacs lisp answer to that question posted: http://codegolf.stackexchange.com/a/44319/18848https://codegolf.stackexchange.com/a/44319/18848
Using the same (while (search) (print)) structure you could modify it into a function to push matches in a buffer to a list and return it like this:
(defun matches-in-buffer (regexp &optional buffer) "return a list of matches of REGEXP in BUFFER or the current buffer if not given." (let ((matches)) (save-match-data (save-excursion (with-current-buffer (or buffer (current-buffer)) (save-restriction (widen) (goto-char 1) (while (search-forward-regexp regexp nil t 1) (push (match-string 0) matches))))) matches)))