From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Valentin Baciu Newsgroups: gmane.emacs.help Subject: Re: Multiline regex Date: Mon, 21 Nov 2011 17:54:39 +0200 Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=20cf305b0c645fe10904b240b4de X-Trace: dough.gmane.org 1321896049 8445 80.91.229.12 (21 Nov 2011 17:20:49 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 21 Nov 2011 17:20:49 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Giles Chamberlin Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Nov 21 18:20:44 2011 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1RSXXs-0003Se-D7 for geh-help-gnu-emacs@m.gmane.org; Mon, 21 Nov 2011 18:20:40 +0100 Original-Received: from localhost ([::1]:40813 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RSXXr-0001Ns-Ht for geh-help-gnu-emacs@m.gmane.org; Mon, 21 Nov 2011 12:20:39 -0500 Original-Received: from eggs.gnu.org ([140.186.70.92]:39065) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RSWCn-0005HU-Sf for help-gnu-emacs@gnu.org; Mon, 21 Nov 2011 10:54:54 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RSWCi-0007tD-Vq for help-gnu-emacs@gnu.org; Mon, 21 Nov 2011 10:54:49 -0500 Original-Received: from mail-yx0-f169.google.com ([209.85.213.169]:60566) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RSWCi-0007sx-No for help-gnu-emacs@gnu.org; Mon, 21 Nov 2011 10:54:44 -0500 Original-Received: by yenm12 with SMTP id m12so1165765yen.0 for ; Mon, 21 Nov 2011 07:54:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=syntactic.org; s=syntacticorg; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=/MXB8eInR/tbQ6Ce+FwU6cLmzaK8Vb9BNjvmKTCwJ1g=; b=c21t0rwe952/pAvh0CEHyZB9q+ej7H1HCoEM17EokaqSEjbiUyp0YOpQ/2FrW1ItO3 PU7kz8pbPCi+Sz+q46THNiCLoCkujarWbn/YBs5vXaJwq1gKN+gimNvKImrn9sZS2ggE I6I4qFbQS7fflr1R+fThKWgq555HTAf5Z5bBA= Original-Received: by 10.236.193.68 with SMTP id j44mr19986686yhn.97.1321890880675; Mon, 21 Nov 2011 07:54:40 -0800 (PST) Original-Received: by 10.146.82.5 with HTTP; Mon, 21 Nov 2011 07:54:39 -0800 (PST) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 209.85.213.169 X-Mailman-Approved-At: Mon, 21 Nov 2011 12:20:35 -0500 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:82995 Archived-At: --20cf305b0c645fe10904b240b4de Content-Type: text/plain; charset=ISO-8859-1 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 > > > --20cf305b0c645fe10904b240b4de Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Hello,

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

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

I think this is hap= pening 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 p= assing 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 reg= ex: 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. =A0Using re-builder (a= nd 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. =A0Any suggestions?




--
Giles



--20cf305b0c645fe10904b240b4de--