Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
code to grab all the strings matching a given regex and put them in a buffer, along with sample use for IPs
(defun collect-regexp-results (regex)
;;; collects all the matches of regex in a buffer called *collect-result*
;;; then switches to that buffer
;;; TODO refactor this to take the region as a parameter
(interactive "Mregex to search for: ")
(let ((curmin (region-or-buffer-beginning))
(curmax (region-or-buffer-end)))
(goto-char curmin)
;; (goto-char (region-or-buffer-beginning))
(while (re-search-forward regex curmax t)
(let ((retval (match-string-no-properties 0)))
(with-current-buffer (get-buffer-create "*collect results*")
(insert retval)
(insert "\n"))))
(switch-to-buffer "*collect results*"))))
(defun collect-ip-addresses ()
(collect-regexp-results "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment