[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

count regexp hits

From: Emanuel Berg
Subject: count regexp hits
Date: Thu, 04 Jan 2018 05:12:42 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)

Just wrote this [1] - is this somewhere already
or is it so simple so you are expected to do it
yourself? If so - well, don't count on it.
I actually know many people incapable of
writing any of this!

(defun count-regexp-hits (regexp)
  (interactive "sregexp: ")
  (let ((hits 0))
      (while (re-search-forward regexp (point-max) t)
        (cl-incf hits) ))
    (message "%d" hits) ))

Example usage - eval me:

%% how many books? (count-regexp-hits "@book")

  author     = {Allan Vaitses},
  ISBN       = {0-07-156914-6},
  publisher  = {International Marine},
  title      = {The Fiberglass Boat Repair Manual},
  year       = 1988

  author     = {Roy Thomas},
  ISBN       = 1616558717,
  publisher  = {Dark Horse},
  title      = {Savage Sword of Conan 22},
  year       = 2016


underground experts united

reply via email to

[Prev in Thread] Current Thread [Next in Thread]