From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Sebastien Le Maguer Newsgroups: gmane.emacs.help Subject: Re: extract lines with regexp Date: Fri, 01 May 2009 23:53:40 +0200 Message-ID: <49FB6F64.1070300@irisa.fr> References: <91723ea9-de6a-4963-918d-b2d53e76b832@p6g2000pre.googlegroups.com> <86skjoddje.fsf@lifelogs.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1241214917 6968 80.91.229.12 (1 May 2009 21:55:17 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 1 May 2009 21:55:17 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri May 01 23:55:09 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1M00hI-0000WH-JQ for geh-help-gnu-emacs@m.gmane.org; Fri, 01 May 2009 23:55:09 +0200 Original-Received: from localhost ([127.0.0.1]:42288 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1M00hH-0004z1-Vd for geh-help-gnu-emacs@m.gmane.org; Fri, 01 May 2009 17:55:08 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1M00gC-0004N0-Cy for help-gnu-emacs@gnu.org; Fri, 01 May 2009 17:54:00 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1M00g7-0004HJ-On for help-gnu-emacs@gnu.org; Fri, 01 May 2009 17:53:59 -0400 Original-Received: from [199.232.76.173] (port=44814 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1M00g7-0004H0-ES for help-gnu-emacs@gnu.org; Fri, 01 May 2009 17:53:55 -0400 Original-Received: from mail4-relais-sop.national.inria.fr ([192.134.164.105]:13716) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.60) (envelope-from ) id 1M00g6-0005tI-SJ for help-gnu-emacs@gnu.org; Fri, 01 May 2009 17:53:55 -0400 X-IronPort-AV: E=Sophos;i="4.40,280,1238968800"; d="scan'208";a="39333259" Original-Received: from arennes-252-1-18-131.w83-195.abo.wanadoo.fr (HELO [192.168.1.69]) ([83.195.25.131]) by mail4-relais-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 01 May 2009 23:53:52 +0200 User-Agent: Thunderbird 2.0.0.21 (X11/20090409) In-Reply-To: <86skjoddje.fsf@lifelogs.com> X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:64135 Archived-At: I was thinking about (forward-line -1) but your solution is simpler. Peter > all lines I want to remove respect the same topology of the ones I want to keep :) Thanks all Sébastien Ted Zlatanov a écrit : > On Thu, 30 Apr 2009 11:57:06 -0700 (PDT) Xah Lee wrote: > > XL> (let (p1 p2) > XL> (save-excursion > XL> (goto-char (point-min)) > XL> (search-forward-regexp "^A.+$") ; begin pattern > XL> (setq p1 (point)) ; save cursor pos > XL> (search-forward-regexp "theq() :") ; ending pattern > XL> (backward-char 8) > XL> (setq p2 (point)) ; save cursor pos > XL> (setq mytext (buffer-substring p1 p2)) > XL> ) > XL> ) > > I don't think your first patten is exactly what the OP needed. > > You can use (forward-line -1) to move the point back to the previous > line, and (beginning-of-line -1) to move to the beginning of the > previous line. Also, you don't need search-forward-regexp the second > time, just search-forward will work. Plus, of course, (backward-char 8) > is just asking for trouble. > > Anyhow, regular expressions can handle multiple lines just fine: > > A > theq() : > non > B > theq() : > > (save-excursion > (goto-char (point-min)) > (while (re-search-forward "\\(.*\\)\ntheq() :" nil t) > (message (match-string 1)))) > > will produce "A" and "B" > > HTH > Ted >