Function: s-count-matches-all
s-count-matches-all is a byte-compiled function defined in s.el.
Signature
(s-count-matches-all REGEXP S &optional START END)
Documentation
Count occurrences of regexp in s.
start, inclusive, and end, exclusive, delimit the part of s to
match. start and end are both indexed starting at 1; the initial
character in s is index 1.
This function starts looking for the next match from the second
character of the previous match. Hence, it counts matches that
overlap a previously found match. To ignore matches that overlap a
previously found match, use s-count-matches.
Source Code
;; Defined in ~/.emacs.d/elpa/s-20220902.1511/s.el
(defun s-count-matches-all (regexp s &optional start end)
"Count occurrences of `regexp' in `s'.
`start', inclusive, and `end', exclusive, delimit the part of `s' to
match. `start' and `end' are both indexed starting at 1; the initial
character in `s' is index 1.
This function starts looking for the next match from the second
character of the previous match. Hence, it counts matches that
overlap a previously found match. To ignore matches that overlap a
previously found match, use `s-count-matches'."
(declare (side-effect-free t))
(let* ((anchored-regexp (format "^%s" regexp))
(match-count 0)
(i 0)
(narrowed-s (substring s (if start (1- start) 0)
(when end (1- end)))))
(save-match-data
(while (< i (length narrowed-s))
(when (s-matches? anchored-regexp (substring narrowed-s i))
(setq match-count (1+ match-count)))
(setq i (1+ i))))
match-count))