From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Cecil Westerhof Newsgroups: gmane.emacs.help Subject: How to combine these two regular expressions Date: Sun, 12 Aug 2012 16:57:18 +0200 Organization: Decebal Computing Message-ID: <87d32w88fl.fsf@Compaq.site> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1344783615 29488 80.91.229.3 (12 Aug 2012 15:00:15 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sun, 12 Aug 2012 15:00:15 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Aug 12 17:00:16 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 1T0ZeG-00045u-Rs for geh-help-gnu-emacs@m.gmane.org; Sun, 12 Aug 2012 17:00:12 +0200 Original-Received: from localhost ([::1]:33705 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T0ZeF-0005xn-Si for geh-help-gnu-emacs@m.gmane.org; Sun, 12 Aug 2012 11:00:11 -0400 Original-Path: usenet.stanford.edu!goblin2!goblin.stu.neva.ru!aioe.org!.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 39 Original-NNTP-Posting-Host: lYLrXPFpjyZ8237ODaoN+w.user.speranza.aioe.org Original-X-Complaints-To: abuse@aioe.org User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux) X-Notice: Filtered by postfilter v. 0.8.2 Cancel-Lock: sha1:GBh8s1fR2yvoCU6FnfT2qAm+UPo= X-Homepage: http://www.decebal.nl/ Original-Xref: usenet.stanford.edu gnu.emacs.help:193950 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:86318 Archived-At: 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. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof