From: Ted Zlatanov <tzz@lifelogs.com>
To: help-gnu-emacs@gnu.org
Subject: Re: extract lines with regexp
Date: Fri, 01 May 2009 10:54:29 -0500 [thread overview]
Message-ID: <86skjoddje.fsf@lifelogs.com> (raw)
In-Reply-To: 91723ea9-de6a-4963-918d-b2d53e76b832@p6g2000pre.googlegroups.com
On Thu, 30 Apr 2009 11:57:06 -0700 (PDT) Xah Lee <xahlee@gmail.com> 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
next prev parent reply other threads:[~2009-05-01 15:54 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <mailman.6302.1241079206.31690.help-gnu-emacs@gnu.org>
2009-04-30 18:57 ` extract lines with regexp Xah Lee
2009-05-01 12:02 ` Sebastien Le Maguer
2009-05-01 16:38 ` Peter Dyballa
2009-05-01 15:54 ` Ted Zlatanov [this message]
2009-05-01 21:53 ` Sebastien Le Maguer
2009-05-04 17:44 ` Raymond Wiker
2009-05-06 11:37 ` no-toppost
2009-05-06 13:33 ` Pascal J. Bourguignon
2009-04-30 8:09 Sebastien LE MAGUER
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=86skjoddje.fsf@lifelogs.com \
--to=tzz@lifelogs.com \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.