From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Ted Zlatanov Newsgroups: gmane.emacs.help Subject: Re: extract lines with regexp Date: Fri, 01 May 2009 10:54:29 -0500 Organization: =?utf-8?B?0KLQtdC+0LTQvtGAINCX0LvQsNGC0LDQvdC+0LI=?= @ Cienfuegos Message-ID: <86skjoddje.fsf@lifelogs.com> References: <91723ea9-de6a-4963-918d-b2d53e76b832@p6g2000pre.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1241196054 16860 80.91.229.12 (1 May 2009 16:40:54 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 1 May 2009 16:40:54 +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 18:40:45 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 1Lzvn2-00007M-Mh for geh-help-gnu-emacs@m.gmane.org; Fri, 01 May 2009 18:40:44 +0200 Original-Received: from localhost ([127.0.0.1]:37252 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Lzvn2-00016d-27 for geh-help-gnu-emacs@m.gmane.org; Fri, 01 May 2009 12:40:44 -0400 Original-Path: news.stanford.edu!headwall.stanford.edu!fu-berlin.de!news.albasani.net!not-for-mail Original-Newsgroups: gnu.emacs.help,comp.emacs Original-Lines: 39 Original-X-Trace: news.albasani.net K8omXhUYRgG5nJu396C9JB+IWRXtFKjnFOCaCk5K8VioXZ2P36OLixVZyIyqa5gaxDJng43mNJKTZVjr2fbQWuaR4z6y1vehdnWvjiCu6w22ZOCoO4MkTuhmT+LELX+r Original-X-Complaints-To: abuse@albasani.net Original-NNTP-Posting-Date: Fri, 1 May 2009 15:49:26 +0000 (UTC) X-User-ID: 3DDYBlc/bSiw4o9aro5wnaM/dRUEtEiXY1HtLyIR8/A= X-Face: bd.DQ~'29fIs`T_%O%C\g%6jW)yi[zuz6; d4V0`@y-~$#3P_Ng{@m+e4o<4P'#(_GJQ%TT= D}[Ep*b!\e,fBZ'j_+#"Ps?s2!4H2-Y"sx" Cancel-Lock: sha1:QpoVOgpv/UyX3PkqQa+p3WzGZuU= sha1:z79myOm59HResn+sRAPKEOuJK94= User-Agent: Gnus/5.110011 (No Gnus v0.11) Emacs/23.0.92 (gnu/linux) X-NNTP-Posting-Host: r9cqKvoSy5DpgrIksMHvJ8kDGCcLgcMiJT0jgSIQdLw= Original-Xref: news.stanford.edu gnu.emacs.help:168857 comp.emacs:98123 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:64133 Archived-At: 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