From: Sebastien Le Maguer <Sebastien.Le_Maguer@irisa.fr>
To: help-gnu-emacs@gnu.org
Subject: Re: extract lines with regexp
Date: Fri, 01 May 2009 23:53:40 +0200 [thread overview]
Message-ID: <49FB6F64.1070300@irisa.fr> (raw)
In-Reply-To: <86skjoddje.fsf@lifelogs.com>
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 <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 21:53 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
2009-05-01 21:53 ` Sebastien Le Maguer [this message]
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=49FB6F64.1070300@irisa.fr \
--to=sebastien.le_maguer@irisa.fr \
--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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).