all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Multiline regex
@ 2011-11-21 13:56 Giles Chamberlin
  2011-11-21 15:41 ` Peter Dyballa
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Giles Chamberlin @ 2011-11-21 13:56 UTC (permalink / raw
  To: help-gnu-emacs

I'm having trouble with a multi line regex: can any one show me where
I'm going wrong?

I have a data file of the form:

a
1
b

a
2
b

and wish to replace the "paragraphs" a..b.  Using re-builder (and based
on http://www.emacswiki.org/emacs/MultilineRegexp) I have constructed a
successfully matching regex:

"a\\(.*
?\\)*?*b"

but when I try to use that regex in replace-regex I get 0 matches.  Any
suggestions?




-- 
Giles




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

* Re: Multiline regex
  2011-11-21 13:56 Multiline regex Giles Chamberlin
@ 2011-11-21 15:41 ` Peter Dyballa
  2011-11-21 15:54 ` Valentin Baciu
  2011-11-21 16:46 ` S Boucher
  2 siblings, 0 replies; 5+ messages in thread
From: Peter Dyballa @ 2011-11-21 15:41 UTC (permalink / raw
  To: Giles Chamberlin; +Cc: help-gnu-emacs


Am 21.11.2011 um 14:56 schrieb Giles Chamberlin:

> Any suggestions?

Just into the blue: real NEWLINEs might be missing at first line's end. They can be entered with C-q C-j.

--
Greetings

  Pete

Only useless documentation transcends the first two laws. 
				– Arnold's Third Law of Documentation




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

* Re: Multiline regex
  2011-11-21 13:56 Multiline regex Giles Chamberlin
  2011-11-21 15:41 ` Peter Dyballa
@ 2011-11-21 15:54 ` Valentin Baciu
  2011-11-22 13:11   ` Giles Chamberlin
  2011-11-21 16:46 ` S Boucher
  2 siblings, 1 reply; 5+ messages in thread
From: Valentin Baciu @ 2011-11-21 15:54 UTC (permalink / raw
  To: Giles Chamberlin; +Cc: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 1110 bytes --]

Hello,

You are probably calling the `replace-regexp' interactively. Try to replace
the regexp with:
a\(.*
?\)*?*b

Otherwise, calling (replace-regexp "a\\(.*
?\\)*?*b", "") from code, in the buffer containing your text should work as
expected.

I think this is happening because how strings are being read and escaped.
In one case you need the \\ since you are calling the function from code
and the backslash has to be escaped. But, when called interactively (using
M-x) you are already passing an "escaped" backslash, so one is sufficient.

On Mon, Nov 21, 2011 at 3:56 PM, Giles Chamberlin <
giles.chamberlin@cisco.com> wrote:

> I'm having trouble with a multi line regex: can any one show me where
> I'm going wrong?
>
> I have a data file of the form:
>
> a
> 1
> b
>
> a
> 2
> b
>
> and wish to replace the "paragraphs" a..b.  Using re-builder (and based
> on http://www.emacswiki.org/emacs/MultilineRegexp) I have constructed a
> successfully matching regex:
>
> "a\\(.*
> ?\\)*?*b"
>
> but when I try to use that regex in replace-regex I get 0 matches.  Any
> suggestions?
>
>
>
>
> --
> Giles
>
>
>

[-- Attachment #2: Type: text/html, Size: 1783 bytes --]

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

* Re: Multiline regex
  2011-11-21 13:56 Multiline regex Giles Chamberlin
  2011-11-21 15:41 ` Peter Dyballa
  2011-11-21 15:54 ` Valentin Baciu
@ 2011-11-21 16:46 ` S Boucher
  2 siblings, 0 replies; 5+ messages in thread
From: S Boucher @ 2011-11-21 16:46 UTC (permalink / raw
  To: Giles Chamberlin, help-gnu-emacs@gnu.org





----- Original Message -----

> and wish to replace the "paragraphs" a..b.  Using re-builder (and 
> based
> on http://www.emacswiki.org/emacs/MultilineRegexp) I have constructed a
> successfully matching regex:
> 
> "a\\(.*
> ?\\)*?*b"

The expression, has some weird things.  * means 0-to-n occurences, ? means 0-or-1 occurences.  So, you probably do not want *?*.

Try M-x regexp-builder

It's a nice interactive way to put together your regexp.



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

* Re: Multiline regex
  2011-11-21 15:54 ` Valentin Baciu
@ 2011-11-22 13:11   ` Giles Chamberlin
  0 siblings, 0 replies; 5+ messages in thread
From: Giles Chamberlin @ 2011-11-22 13:11 UTC (permalink / raw
  To: help-gnu-emacs

Valentin Baciu <valentin@syntactic.org> writes:

> You are probably calling the `replace-regexp' interactively. Try to replace
> the regexp with:
> a\(.*
> ?\)*?*b

That was exactly it thanks.  I was running this interactively and once
I fixed the escaping all was well.  Off to re-read the regex section of
the manual.

-- 
Giles 





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

end of thread, other threads:[~2011-11-22 13:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-21 13:56 Multiline regex Giles Chamberlin
2011-11-21 15:41 ` Peter Dyballa
2011-11-21 15:54 ` Valentin Baciu
2011-11-22 13:11   ` Giles Chamberlin
2011-11-21 16:46 ` S Boucher

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.