Skip to content

Instantly share code, notes, and snippets.

@MrGung
Created November 22, 2010 18:06
Show Gist options
  • Save MrGung/710353 to your computer and use it in GitHub Desktop.
Save MrGung/710353 to your computer and use it in GitHub Desktop.
extract-regex
(defun extract-regex (regexp)
"Extracts all occurrences of regexp from the current buffer."
(interactive "sRegexp for extraction: ")
(setq result '())
(save-excursion
(beginning-of-buffer)
(while (re-search-forward regexp nil t)
(when (match-string 0) ; Got a match
(setq result (cons (match-string 0) result)))))
(let ((result-string (mapconcat 'identity result "\n")))
(message result-string)
result-string))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment