how-many (aliased count-matches ) does this, but works on buffers.
Here's what works with strings:
(defun how-many-str (regexp str) (loop with start = 0 for count from 0 while (string-match regexp str start) do (setq start (match-end 0)) finally return count))
event_jr
source share