I have the following function that uses a regexp for counting matches, but I have difficulty coming up with regexp expressions to test it.
(defun rk-regex-count (regex rgn-beg rgn-end) "Count brace marks within a region with `completing-read'. REGEX Regular expression. RGN-BEG Marker defining start of region. RGN-END Marker defining end of region." (interactive (list (read-regexp "Regex: ") (region-beginning) (region-end))) (save-excursion (let (($sum 0)) (goto-char rgn-beg) (while (and (< (point) rgn-end) (re-search-forward regex rgn-end t)) (+ $sum 1)) (message "Marks: %s Count: %d" regex $sum) (goto-char rgn-beg))))
For instance, suppose I have the following piece of code and want to count the number of opening parentheses. What should my regex be? Other examples or using this function would be very illuminating.
(interactive (list (read-regexp "Regex: ") (region-beginning) (region-end)))