From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Emanuel Berg Newsgroups: gmane.emacs.help Subject: count regexp hits Date: Thu, 04 Jan 2018 05:12:42 +0100 Organization: Aioe.org NNTP Server Message-ID: <86shbmcldx.fsf@zoho.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1515039217 27269 195.159.176.226 (4 Jan 2018 04:13:37 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 4 Jan 2018 04:13:37 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Jan 04 05:13:33 2018 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eWwuI-0006eA-3h for geh-help-gnu-emacs@m.gmane.org; Thu, 04 Jan 2018 05:13:30 +0100 Original-Received: from localhost ([::1]:47212 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eWwwF-0000xT-OV for geh-help-gnu-emacs@m.gmane.org; Wed, 03 Jan 2018 23:15:31 -0500 X-Received: by 10.28.189.85 with SMTP id n82mr360352wmf.23.1515039164165; Wed, 03 Jan 2018 20:12:44 -0800 (PST) Original-Path: usenet.stanford.edu!a71no96893wme.0!news-out.google.com!a84ni886wmc.0!nntp.google.com!proxad.net!feeder1-2.proxad.net!news.mixmin.net!aioe.org!.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 39 Original-NNTP-Posting-Host: zRXoCvQ6k9fneBfYPnB6lQ.user.gioia.aioe.org Original-X-Complaints-To: abuse@aioe.org Cancel-Lock: sha1:M1TB4xVxb7hxQ1kBGSH4f0oHRJw= Mail-Copies-To: never X-Notice: Filtered by postfilter v. 0.8.2 Original-Xref: usenet.stanford.edu gnu.emacs.help:221447 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:115562 Archived-At: 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)) (save-excursion (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") @book{fiberglass-boat-repair-manual, author = {Allan Vaitses}, ISBN = {0-07-156914-6}, publisher = {International Marine}, title = {The Fiberglass Boat Repair Manual}, year = 1988 } @book{savage-sword-of-conan-22, author = {Roy Thomas}, ISBN = 1616558717, publisher = {Dark Horse}, title = {Savage Sword of Conan 22}, year = 2016 } [1] http://user.it.uu.se/~embe8573/emacs-init/count.el -- underground experts united http://user.it.uu.se/~embe8573