how-many is an interactive compiled Lisp function in ‘replace.el’.
(how-many REGEXP &optional RSTART REND INTERACTIVE)
Print and return number of matches for REGEXP following point. When called from Lisp and INTERACTIVE is omitted or nil, just return the number, do not print it; if INTERACTIVE is t, the function behaves in all respects as if it had been called interactively.
If REGEXP contains upper case characters (excluding those preceded by ‘\’) and ‘search-upper-case’ is non-nil, the matching is case-sensitive.
Second and third arg RSTART and REND specify the region to operate on.
Interactively, in Transient Mark mode when the mark is active, operate on the contents of the region. Otherwise, operate from point to the end of (the accessible portion of) the buffer.
This function starts looking for the next match from the end of the previous match. Hence, it ignores matches that overlap a previously found match.