Article View: gnu.emacs.help
Article #188863Re: Newlines in regexps
From: Silver
Date: Mon, 27 May 1991 22:42
Date: Mon, 27 May 1991 22:42
35 lines
2229 bytes
2229 bytes
dsmith@spam.ua.oz.au (David Smith) writes:
> Say for example I want to convert standard quotes (like "arglebarge") into
> TeX-style quotes (like ``arglebarge''), but where the quote can span one ore
> more lines. I've tried things like regexp-replacing "\(\(^J\|.\)*\)" with
> ``\1'', but the newline seems to cause problems.
About the best I can come up with is:
(replace-regexp "\"\\([^\"]*\\)\"" "``\\1''")
The first regexp matches `a doublequote followed by any number of
non-doublequotes followed by a doublequote'. If invoked interactively, the
dialogue would appear as follows:
M-x replace-regexp
Replace regexp: "\([^"]*\)"
Replace regexp "\([^"]*\)" with: ``\1''
Incidentally, "[\000-\377]", `the class of characters whose ascii values are
between (inclusive) 0 and 255', is the best way I can think of to say `any
character'.
> Of course, to get the newline I have to use quoted-insert, but when I enter
> it it clears the minibuffer (but it still gets inserted into the regexp).
Editing in the minibuffer is similar to editing in any other buffer. Try some
standard editing commands in the minibuffer, like C-n and C-p, and you'll see
that you can edit a multi-lined value without problem. And if you feel
uncomfortable editing text in a one-lined window, simply increase it's size
(C-x ^ is usually bound to enlarge-window).
> But the above regexp still doesn't work!
Worked for me... In fact, what I supplied is equivalent. "\\(\n\\|.\\)" is
the same as "[\000-\377]" but for the side effect of using the grouping
operator.
Regards, [Ag]
Technical Details
Message-ID:
<May.27.18.42.50.1991.29230@paul.rutgers.edu>Path:
arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!cis.ohio-state.edu!tut.cis.ohio-state.edu!rutgers!aramis.rutgers.edu!paul.rutgers.edu!gaynorReferences:
<DSMITH.91May25125350@spam.ua.oz.au>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103b8b,4118438ef0f66e70 X-Google-Attributes: gid103b8b,public X-Google-ArrivalTime: 1991-05-28 08:20:27 PST Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!cis.ohio-state.edu!tut.cis.ohio-state.edu!rutgers!aramis.rutgers.edu!paul.rutgers.edu!gaynor From: gaynor@paul.rutgers.edu (Silver) Newsgroups: gnu.emacs.help Subject: Re: Newlines in regexps Message-ID: <May.27.18.42.50.1991.29230@paul.rutgers.edu> Date: 27 May 91 22:42:50 GMT References: <DSMITH.91May25125350@spam.ua.oz.au> Distribution: gnu Organization: Rutgers Univ., New Brunswick, N.J. Lines: 35