From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Drew Adams Newsgroups: gmane.emacs.help Subject: RE: count regexp hits Date: Wed, 3 Jan 2018 21:02:02 -0800 (PST) Message-ID: References: <86shbmcldx.fsf@zoho.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1515042051 8012 195.159.176.226 (4 Jan 2018 05:00:51 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 4 Jan 2018 05:00:51 +0000 (UTC) To: Emanuel Berg , help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Jan 04 06:00:47 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 1eWxe1-0001d0-BD for geh-help-gnu-emacs@m.gmane.org; Thu, 04 Jan 2018 06:00:45 +0100 Original-Received: from localhost ([::1]:47309 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eWxg0-0004Wa-KH for geh-help-gnu-emacs@m.gmane.org; Thu, 04 Jan 2018 00:02:48 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:45844) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eWxfY-0004WJ-FH for help-gnu-emacs@gnu.org; Thu, 04 Jan 2018 00:02:21 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eWxfV-00039V-E4 for help-gnu-emacs@gnu.org; Thu, 04 Jan 2018 00:02:20 -0500 Original-Received: from aserp2120.oracle.com ([141.146.126.78]:37382) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eWxfV-00037u-3u for help-gnu-emacs@gnu.org; Thu, 04 Jan 2018 00:02:17 -0500 Original-Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.21/8.16.0.21) with SMTP id w0451wDH011153; Thu, 4 Jan 2018 05:02:04 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=mime-version : message-id : date : from : sender : to : subject : references : in-reply-to : content-type : content-transfer-encoding; s=corp-2017-10-26; bh=ExdFeMfaONsajqMkYfm6RbrgMR+3OjQYcbnJRfacDus=; b=wMBgkDt2u0j3ZNEkQN/+dm4CeJAnZLA0V/UPyastWrrMmEqC18dRXqWuDyZvOBArflk+ VTj0gOOa1w6xkV0emViPrv5e0ILgdgzO9QrGgIqZxZqPpac5WJNKehOMYtHC2DI2QwXZ 81WP2MCoE4u3/DXiTpS5zGdz3UJLDL5Ya4+SpmIdrvjvpoJrEXzz4LY5CUgCtpQX5Y99 yA81OCaL1NsVBSEZXsXFtPeztVizZcMfGQOLyMbCPM9GOTTcUcXk3IPisKtOfUY8xxhg GSMkAXr/M9Foca8tvh1xmeF5KmgzdLxCw6Tq9Uya76JY2tnOcGJfWSVCPNfpV2mURSCV Cw== Original-Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by aserp2120.oracle.com with ESMTP id 2f9c989cvs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 04 Jan 2018 05:02:04 +0000 Original-Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w04524sW007431 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 4 Jan 2018 05:02:04 GMT Original-Received: from abhmp0007.oracle.com (abhmp0007.oracle.com [141.146.116.13]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w04523K8014416; Thu, 4 Jan 2018 05:02:03 GMT In-Reply-To: <86shbmcldx.fsf@zoho.com> X-Priority: 3 X-Mailer: Oracle Beehive Extensions for Outlook 2.0.1.9.1 (1003210) [OL 16.0.4627.0 (x86)] X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8763 signatures=668651 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=849 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1801040068 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 141.146.126.78 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:115563 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! >=20 > (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) )) `C-h f count-matches': count-matches is an alias for `how-many' in `replace.el'. (count-matches 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.