From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Jambunathan K Newsgroups: gmane.emacs.help Subject: Re: How to combine these two regular expressions Date: Mon, 13 Aug 2012 00:14:16 +0530 Message-ID: <877gt4j6gv.fsf@gmail.com> References: <87d32w88fl.fsf@Compaq.site> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1344797068 4737 80.91.229.3 (12 Aug 2012 18:44:28 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sun, 12 Aug 2012 18:44:28 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Cecil Westerhof Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Aug 12 20:44:28 2012 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1T0d9F-00034J-Rn for geh-help-gnu-emacs@m.gmane.org; Sun, 12 Aug 2012 20:44:25 +0200 Original-Received: from localhost ([::1]:50105 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T0d9E-0007MH-VQ for geh-help-gnu-emacs@m.gmane.org; Sun, 12 Aug 2012 14:44:24 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:54310) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T0d98-0007Go-3r for help-gnu-emacs@gnu.org; Sun, 12 Aug 2012 14:44:20 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T0d95-0005lG-QN for help-gnu-emacs@gnu.org; Sun, 12 Aug 2012 14:44:18 -0400 Original-Received: from mail-pb0-f41.google.com ([209.85.160.41]:41529) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T0d95-0005lA-K5 for help-gnu-emacs@gnu.org; Sun, 12 Aug 2012 14:44:15 -0400 Original-Received: by pbbro12 with SMTP id ro12so6644294pbb.0 for ; Sun, 12 Aug 2012 11:44:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-type; bh=rZXYQ0Ly0+nsr0MyCbk5Ok2lHbcUJehjWsBidEdbQqU=; b=y4+iWPhXH2Vn+7+MoPjy8Jfz5wjo0tZRXfVeecx6PFt5cAVYgn4Tc+8Uu0pmUMi9r4 qZIQ+LtXa+KGvS38n46XoUkVQqR0IlOnF0nmr32bkZBSCWS5atXYj+6LWW0jLI5itOQk jubGN7TghISDtL6eylK9S9dhIXUoRhifTsv1k2oyrqy5B2rNhw06pna7ablc+6MO1vpv G6C1+dbmavk+nGkc0OSYi+8+XGlmX2lMGm0JK7o8YYVzA6ANImDXMbf884LnCPvH1IIR J15vxYkLWAyRvYzzjPIe0ucuLExcOQrOxjVaq38nby1razJwIx7hMz7aW1TtE0scdjwb DYxg== Original-Received: by 10.66.82.97 with SMTP id h1mr13082745pay.45.1344797054752; Sun, 12 Aug 2012 11:44:14 -0700 (PDT) Original-Received: from debian-6.05 ([101.62.48.22]) by mx.google.com with ESMTPS id tg9sm1913795pbc.53.2012.08.12.11.44.12 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 12 Aug 2012 11:44:14 -0700 (PDT) In-Reply-To: <87d32w88fl.fsf@Compaq.site> (Cecil Westerhof's message of "Sun, 12 Aug 2012 16:57:18 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.160.41 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 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-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:86320 Archived-At: You should provide a human-readable description of what the regexes are trying to do. Have you tried: C-h f regexp-opt RET Cecil Westerhof writes: > I was asked by someone for a regular expression that could combine > several search patterns, so that a file only needs to be scanned ones > and not several times. I was partly successful, but I still need two > passes. > > I now have the following code: > (defun dcbl-search-heading () > (interactive) > (re-search-forward "\\(. > \\)\\( > > \\)\\(.+ > \\)\\( > ?.+ > \\)" nil t) > (replace-match "\\1 > #heading# > \\4")) > > (defun dcbl-search-heading2 () > (interactive) > (re-search-forward "\\(. > \\)\\( > \\)\\(.+ > \\)\\(\\\(.+ > \\\)+\\)" nil t) > (replace-match "\\1 > #heading# > \\4")) > > Is there a way to combine those regular expressions to one? > > By the way, if the used expressions could be optimised, let me know. I > do not make them often, thus maybe I do things sub-optimal here. --