[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))
(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
- count regexp hits,
Emanuel Berg <=
- RE: count regexp hits, Drew Adams, 2018/01/04
- Message not available
- Re: count regexp hits, Emanuel Berg, 2018/01/04
- Re: DWIM region (was: Re: count regexp hits), Kaushal Modi, 2018/01/04
- Message not available
- Re: DWIM region (was: Re: count regexp hits), Emanuel Berg, 2018/01/04
- Re: DWIM region (was: Re: count regexp hits), Kaushal Modi, 2018/01/04
- Message not available
- Re: DWIM region (was: Re: count regexp hits), Emanuel Berg, 2018/01/04
- advice vs hooks in org (was DWIM region), Rusi, 2018/01/08