Skip to main content
1 of 2
Jordon Biondo
  • 12.7k
  • 2
  • 46
  • 63

I have an emacs lisp answer to that question posted: http://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))) 
Jordon Biondo
  • 12.7k
  • 2
  • 46
  • 63