all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* how can I make regexp expression effective across many lines
@ 2007-01-29 21:01 Michael Chen
  2007-01-29 21:16 ` Lennart Borgman (gmail)
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Michael Chen @ 2007-01-29 21:01 UTC (permalink / raw)
  To: help-gnu-emacs

Hi, there, I have problem with newlines in regexp. Here is what I want
to do: delete anything between <FORM> to TIP OF THE WEEK inclusively.
There are many lines in between. Any regex I tried can not go through
the newline. Any idea? Thanks.

Michael Chen

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: how can I make regexp expression effective across many lines
  2007-01-29 21:01 how can I make regexp expression effective across many lines Michael Chen
@ 2007-01-29 21:16 ` Lennart Borgman (gmail)
  2007-01-29 21:40 ` Drew Adams
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 9+ messages in thread
From: Lennart Borgman (gmail) @ 2007-01-29 21:16 UTC (permalink / raw)
  To: Michael Chen; +Cc: help-gnu-emacs

Michael Chen wrote:
> Hi, there, I have problem with newlines in regexp. Here is what I want
> to do: delete anything between <FORM> to TIP OF THE WEEK inclusively.
> There are many lines in between. Any regex I tried can not go through
> the newline. Any idea? Thanks.
> 
> Michael Chen


Maybe this helps:

   http://www.emacswiki.org/cgi-bin/wiki/SymbolicRegexp

I have not looked at sregex myself, but I looked a bit at rx.el.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: how can I make regexp expression effective across many lines
       [not found] <mailman.3753.1170104495.2155.help-gnu-emacs@gnu.org>
@ 2007-01-29 21:26 ` Pascal Bourguignon
  0 siblings, 0 replies; 9+ messages in thread
From: Pascal Bourguignon @ 2007-01-29 21:26 UTC (permalink / raw)
  To: help-gnu-emacs

         "Michael Chen" <vancouver.michael@gmail.com> writes:

> Hi, there, I have problem with newlines in regexp. Here is what I want
> to do: delete anything between <FORM> to TIP OF THE WEEK inclusively.
> There are many lines in between. Any regex I tried can not go through
> the newline. Any idea? Thanks.

Well, . matches anything but a newline. So you could build a regexp
matching anything including a newline as: "\\(.\\|\n\\)*"

Now, you want it shy, to find the first occurence of "TIP OF THE
WEEK", so use *? instead of *

"<FORM>\\(.\\|\n\\)*?TIP OF THE WEEK"



But in lisp code, it's easier to just search the start tag and then
search the end tag:

 (delete-region
     (if (search-forward "<FORM>")
        (match-beginning 0)
        (error "No <FORM>"))
     (if (search-forward "TIP OF THE WEEK")
        (match-end 0)
        (error "No TIP OF THE WEEK")))

no need for a regexp here...     
           

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

PLEASE NOTE: Some quantum physics theories suggest that when the
consumer is not directly observing this product, it may cease to
exist or will exist only in a vague and undetermined state.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: how can I make regexp expression effective across many lines
  2007-01-29 21:01 how can I make regexp expression effective across many lines Michael Chen
  2007-01-29 21:16 ` Lennart Borgman (gmail)
@ 2007-01-29 21:40 ` Drew Adams
  2007-01-29 21:47   ` Drew Adams
  2007-01-29 22:11 ` Peter Dyballa
       [not found] ` <mailman.3755.1170105424.2155.help-gnu-emacs@gnu.org>
  3 siblings, 1 reply; 9+ messages in thread
From: Drew Adams @ 2007-01-29 21:40 UTC (permalink / raw)
  To: Michael Chen, help-gnu-emacs

> Hi, there, I have problem with newlines in regexp. Here is what I want
> to do: delete anything between <FORM> to TIP OF THE WEEK inclusively.
> There are many lines in between. Any regex I tried can not go through
> the newline. Any idea? Thanks.

 . matches any character except a newline character.
 [^\n] matches any character.

Interactively, use C-q C-j to insert a newline character itself in the
regexp, in place of \n. See the Elisp manual, node Syntax of Regexps, in
particular about the treatment of backslash.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: how can I make regexp expression effective across many lines
  2007-01-29 21:40 ` Drew Adams
@ 2007-01-29 21:47   ` Drew Adams
  0 siblings, 0 replies; 9+ messages in thread
From: Drew Adams @ 2007-01-29 21:47 UTC (permalink / raw)
  To: Michael Chen, help-gnu-emacs

>  . matches any character except a newline character.
>  [^\n] matches any character.

Oops. I should have said \(.\|\n\). In Lisp, that's \\(.\\|\n\\).
Asleep at the wheel...

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: how can I make regexp expression effective across many lines
  2007-01-29 21:01 how can I make regexp expression effective across many lines Michael Chen
  2007-01-29 21:16 ` Lennart Borgman (gmail)
  2007-01-29 21:40 ` Drew Adams
@ 2007-01-29 22:11 ` Peter Dyballa
       [not found] ` <mailman.3755.1170105424.2155.help-gnu-emacs@gnu.org>
  3 siblings, 0 replies; 9+ messages in thread
From: Peter Dyballa @ 2007-01-29 22:11 UTC (permalink / raw)
  To: Michael Chen; +Cc: help-gnu-emacs


Am 29.01.2007 um 22:01 schrieb Michael Chen:

> Hi, there, I have problem with newlines in regexp. Here is what I want
> to do: delete anything between <FORM> to TIP OF THE WEEK inclusively.
> There are many lines in between. Any regex I tried can not go through
> the newline. Any idea?

Make it look for something that's not between beginning and end. For  
example

	<FORM>[^·]*TIP OF THE WEEK

This greedy expression would find (and delete) everything between the  
first <FORM> it finds and the last TIP OF THE WEEK in the buffer. So  
you better use the improved form:

	<FORM>[^·]*?TIP OF THE WEEK

--
Greetings

   Pete

Upgraded:  Didn't work the first time.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: how can I make regexp expression effective across many lines
       [not found] ` <mailman.3755.1170105424.2155.help-gnu-emacs@gnu.org>
@ 2007-01-29 23:00   ` Mark Elston
  0 siblings, 0 replies; 9+ messages in thread
From: Mark Elston @ 2007-01-29 23:00 UTC (permalink / raw)
  To: help-gnu-emacs

* Lennart Borgman (gmail) wrote (on 1/29/2007 1:16 PM):
> Michael Chen wrote:
>> Hi, there, I have problem with newlines in regexp. Here is what I want
>> to do: delete anything between <FORM> to TIP OF THE WEEK inclusively.
>> There are many lines in between. Any regex I tried can not go through
>> the newline. Any idea? Thanks.
>>
>> Michael Chen
> 
> 
> Maybe this helps:
> 
>   http://www.emacswiki.org/cgi-bin/wiki/SymbolicRegexp
> 
> I have not looked at sregex myself, but I looked a bit at rx.el.
> 
> 

You live and learn.  I wish I had learned this *last* week! :)

Mark

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: how can I make regexp expression effective across many lines
       [not found] <mailman.3757.1170107259.2155.help-gnu-emacs@gnu.org>
@ 2007-01-29 23:05 ` Pascal Bourguignon
  2007-01-29 23:52   ` Drew Adams
  0 siblings, 1 reply; 9+ messages in thread
From: Pascal Bourguignon @ 2007-01-29 23:05 UTC (permalink / raw)
  To: help-gnu-emacs

"Drew Adams" <drew.adams@oracle.com> writes:

>>  . matches any character except a newline character.
>>  [^\n] matches any character.
>
> Oops. I should have said \(.\|\n\). In Lisp, that's \\(.\\|\n\\).
> Asleep at the wheel...

Not exactly.  It's:

\(.\|
\)

(if you must enter it in the minibuffer for example, typing C-q C-j to
insert the newline), or the result of evaluating: "\\(.\\|\n\\)" (if
you type it in an elisp program).

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

There is no worse tyranny than to force a man to pay for what he does not
want merely because you think it would be good for him. -- Robert Heinlein

^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: how can I make regexp expression effective across many lines
  2007-01-29 23:05 ` Pascal Bourguignon
@ 2007-01-29 23:52   ` Drew Adams
  0 siblings, 0 replies; 9+ messages in thread
From: Drew Adams @ 2007-01-29 23:52 UTC (permalink / raw)
  To: Pascal Bourguignon, help-gnu-emacs

>    > \(.\|\n\). In Lisp, that's \\(.\\|\n\\).
>
> Not exactly.  It's: \(.\|
> \)
>
> (if you must enter it in the minibuffer for example, typing C-q C-j to
> insert the newline),

That's what I meant by "Interactively, use C-q C-j to insert a newline
character itself in the regexp, in place of \n."

> or the result of evaluating: "\\(.\\|\n\\)" (if
> you type it in an elisp program).

That's what I meant by "In Lisp, that's \\(.\\|\n\\)."

;-)

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2007-01-29 23:52 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-01-29 21:01 how can I make regexp expression effective across many lines Michael Chen
2007-01-29 21:16 ` Lennart Borgman (gmail)
2007-01-29 21:40 ` Drew Adams
2007-01-29 21:47   ` Drew Adams
2007-01-29 22:11 ` Peter Dyballa
     [not found] ` <mailman.3755.1170105424.2155.help-gnu-emacs@gnu.org>
2007-01-29 23:00   ` Mark Elston
     [not found] <mailman.3753.1170104495.2155.help-gnu-emacs@gnu.org>
2007-01-29 21:26 ` Pascal Bourguignon
     [not found] <mailman.3757.1170107259.2155.help-gnu-emacs@gnu.org>
2007-01-29 23:05 ` Pascal Bourguignon
2007-01-29 23:52   ` Drew Adams

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.