From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Doug Lewan Newsgroups: gmane.emacs.help Subject: RE: How to combine these two regular expressions Date: Mon, 13 Aug 2012 14:08:26 +0000 Message-ID: <155DEC68569B714B86C2C7075F5EDA98268CCDB0@DAKIYA1.pegasus.local> References: <87d32w88fl.fsf@Compaq.site> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1344866905 1963 80.91.229.3 (13 Aug 2012 14:08:25 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 13 Aug 2012 14:08:25 +0000 (UTC) To: Cecil Westerhof , "help-gnu-emacs@gnu.org" Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Aug 13 16:08:24 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 1T0vJV-0004aX-VQ for geh-help-gnu-emacs@m.gmane.org; Mon, 13 Aug 2012 16:08:14 +0200 Original-Received: from localhost ([::1]:55501 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T0vJU-0001Gq-TU for geh-help-gnu-emacs@m.gmane.org; Mon, 13 Aug 2012 10:08:12 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:56324) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T0vJK-0001GX-ST for help-gnu-emacs@gnu.org; Mon, 13 Aug 2012 10:08:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T0vJJ-00034i-DZ for help-gnu-emacs@gnu.org; Mon, 13 Aug 2012 10:08:02 -0400 Original-Received: from mailhost.shubertorg.com ([207.246.209.200]:33001 helo=webmail.shubertorg.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T0vJJ-00034e-9k for help-gnu-emacs@gnu.org; Mon, 13 Aug 2012 10:08:01 -0400 Original-Received: from dakiya1.pegasus.local ([::1]) by DAKIYA1.pegasus.local ([::1]) with mapi id 14.01.0339.001; Mon, 13 Aug 2012 10:08:27 -0400 Thread-Topic: How to combine these two regular expressions Thread-Index: AQHNeJs9zPPA9oA9lUSOr4dUNquz5JdXx/Fw In-Reply-To: <87d32w88fl.fsf@Compaq.site> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.0.21.202] X-detected-operating-system: by eggs.gnu.org: Windows XP/2000 (RFC1323+, w+, tstamp-) X-Received-From: 207.246.209.200 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:86329 Archived-At: The most common way to "combine" two regular expressions is the form "\\(RE= 1\\|RE2\\)". I usually do this with variables (concat "\\(" re-1 "\\|" re-2 "\\)"). There's also the form "\\(?:...\\)" if you don't care about match data or "= \\(?N:...\\)" if you care very much about it. (N is an integer and forces t= his match to become match number N.) I hope this helps. ,Doug > -----Original Message----- > From: help-gnu-emacs-bounces+dougl=3Dshubertticketing.com@gnu.org > [mailto:help-gnu-emacs-bounces+dougl=3Dshubertticketing.com@gnu.org] On > Behalf Of Cecil Westerhof > Sent: Sunday, 2012 August 12 10:57 > To: help-gnu-emacs@gnu.org > Subject: How to combine these two regular expressions >=20 > 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. >=20 > I now have the following code: > (defun dcbl-search-heading () > (interactive) > (re-search-forward "\\(. > \\)\\( >=20 > \\)\\(.+ > \\)\\( > ?.+ > \\)" nil t) > (replace-match "\\1 > #heading# > \\4")) >=20 > (defun dcbl-search-heading2 () > (interactive) > (re-search-forward "\\(. > \\)\\( > \\)\\(.+ > \\)\\(\\\(.+ > \\\)+\\)" nil t) > (replace-match "\\1 > #heading# > \\4")) >=20 > Is there a way to combine those regular expressions to one? >=20 > 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. >=20 > -- > Cecil Westerhof > Senior Software Engineer > LinkedIn: http://www.linkedin.com/in/cecilwesterhof