all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
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 14:02:10 +0200	[thread overview]
Message-ID: <49FAE4C2.8070509@irisa.fr> (raw)
In-Reply-To: <91723ea9-de6a-4963-918d-b2d53e76b832@p6g2000pre.googlegroups.com>

In fact I need just the line before theq ().

All lines, except thoses which begin with  "theq", respect the same 
topology :
../rep1/rep2/nom_ficXXX_refXX_sentX.wav

I can use your code to build what what I want. I will send my solution 
when it will be finished

Thanks a lot

Xah Lee a écrit :
> On Apr 30, 1:09 am, Sebastien LE MAGUER <Sebastien.Le_mag...@irisa.fr>
> wrote:
>   
>> Hi,
>>
>> I wonder how to extract lines using a regexp. My file contains something
>> like that :
>>
>> <useless lines>
>> <line X>
>> theq() :
>> <useless lines>
>>
>> and I want to extract all lines before theq (here line X)
>>
>> does anyone have an idea ?
>>     
>
> regex is very limited in extracting text that span multiple lines.
>
> what you want can be done in emacs, but we need a bit more detail. For
> example, what pattern does the lines you want start? “All lines before
> theq” doesn't specify how it starts.
>
> A better solution is to use search-forward-regexp to search the begin
> pattern, mark, then search-forward-regexp again to search for the
> ending pattern “theq() :”, then do search-backward-regexp to move
> point to the beginning of “theq”. Then, grab the region.
>
> here's some pieces of code (untested):
>
> (let (p1 p2)
>   (save-excursion
>     (goto-char (point-min))
>     (search-forward-regexp "^A.+$") ; begin pattern
>     (setq p1 (point)) ; save cursor pos
>     (search-forward-regexp "theq() :") ; ending pattern
>     (backward-char 8)
>     (setq p2 (point)) ; save cursor pos
>     (setq mytext (buffer-substring p1 p2))
>     )
>   )
>
>   Xah
> ∑ http://xahlee.org/
>
> ☄
>   





  reply	other threads:[~2009-05-01 12:02 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 [this message]
2009-05-01 16:38     ` Peter Dyballa
2009-05-01 15:54   ` Ted Zlatanov
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=49FAE4C2.8070509@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.
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.