* replace-regexp question
@ 2003-06-02 11:21 Chang Luo
2003-06-02 11:53 ` lawrence mitchell
0 siblings, 1 reply; 12+ messages in thread
From: Chang Luo @ 2003-06-02 11:21 UTC (permalink / raw)
I want to replace regexp "a$" to "a$b$c$". how to do that?
i.e. I want:
a -> a
b
c
But replace-regexp gives me:
a -> a$b$c$
Thanks!
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: replace-regexp question
2003-06-02 11:21 Chang Luo
@ 2003-06-02 11:53 ` lawrence mitchell
0 siblings, 0 replies; 12+ messages in thread
From: lawrence mitchell @ 2003-06-02 11:53 UTC (permalink / raw)
Chang Luo wrote:
> I want to replace regexp "a$" to "a$b$c$". how to do that?
> i.e. I want:
> a -> a
> b
> c
> But replace-regexp gives me:
> a -> a$b$c$
"$" is only a special character in regexps in the search string
(not the replace string). Hence, you want to do something like
(replace-regexp "a$" "a\nb\nc\n"). If doing this interactively,
"\n" is also interpreted literally. So you have to insert an
literal newline, using C-q C-j, e.g. the interactive key
sequence would be:
M-x replace-regexp RET a $ RET a C-q C-j b C-q C-j c C-q C-j RET
hope the clears that up a bit.
--
lawrence mitchell <wence@gmx.li>
^ permalink raw reply [flat|nested] 12+ messages in thread
* replace-regexp question
@ 2005-10-26 17:15 Neon Absentius
0 siblings, 0 replies; 12+ messages in thread
From: Neon Absentius @ 2005-10-26 17:15 UTC (permalink / raw)
Is there a way to use the command replace-regexp to replace a number with
that number increased, say, by 15? I tried
C-M-% -?[0-9]+ RET (number-to-string (+ (string-to-number "\&") 15)) RET
but it doesn't work because emacs interprets the second input to be a string
and so it doesn't evaluate it. So I guess the question is how can we use
the result of evaluating a sexp for replacement text?
Any help and/or pointers to documentation will be greatly appreciated.
--
There is no national science just as there is no national
multiplication table; what is national is no longer science.
-- Anton Checov
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: replace-regexp question
[not found] <mailman.12812.1130346970.20277.help-gnu-emacs@gnu.org>
@ 2005-10-26 17:34 ` David Kastrup
2005-10-26 18:24 ` Giorgos Keramidas
` (2 more replies)
0 siblings, 3 replies; 12+ messages in thread
From: David Kastrup @ 2005-10-26 17:34 UTC (permalink / raw)
Neon Absentius <absent@sdf.lonestar.org> writes:
> Is there a way to use the command replace-regexp to replace a number with
> that number increased, say, by 15? I tried
>
> C-M-% -?[0-9]+ RET (number-to-string (+ (string-to-number "\&") 15)) RET
>
> but it doesn't work because emacs interprets the second input to be
> a string and so it doesn't evaluate it. So I guess the question is
> how can we use the result of evaluating a sexp for replacement text?
>
> Any help and/or pointers to documentation will be greatly
> appreciated.
The development version of Emacs would offer
C-M-% -?[0-9]+ RET \,(+ \#& 15) RET
--
David Kastrup, Kriemhildstr. 15, 44793 Bochum
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: replace-regexp question
2005-10-26 17:34 ` replace-regexp question David Kastrup
@ 2005-10-26 18:24 ` Giorgos Keramidas
2005-10-26 19:52 ` David Kastrup
2005-10-27 11:47 ` Neon Absentius
2005-10-27 14:38 ` Sébastien Kirche
2 siblings, 1 reply; 12+ messages in thread
From: Giorgos Keramidas @ 2005-10-26 18:24 UTC (permalink / raw)
David Kastrup <dak@gnu.org> writes:
>Neon Absentius <absent@sdf.lonestar.org> writes:
>> Is there a way to use the command replace-regexp to replace a number with
>> that number increased, say, by 15? I tried
>>
>> C-M-% -?[0-9]+ RET (number-to-string (+ (string-to-number "\&") 15)) RET
>>
>> but it doesn't work because emacs interprets the second input to be
>> a string and so it doesn't evaluate it. So I guess the question is
>> how can we use the result of evaluating a sexp for replacement text?
>>
>> Any help and/or pointers to documentation will be greatly
>> appreciated.
>
> The development version of Emacs would offer
> C-M-% -?[0-9]+ RET \,(+ \#& 15) RET
Oh, heh! Very neat ;)
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: replace-regexp question
2005-10-26 18:24 ` Giorgos Keramidas
@ 2005-10-26 19:52 ` David Kastrup
2005-10-27 9:01 ` Harald Hanche-Olsen
0 siblings, 1 reply; 12+ messages in thread
From: David Kastrup @ 2005-10-26 19:52 UTC (permalink / raw)
Giorgos Keramidas <keramida@ceid.upatras.gr> writes:
> David Kastrup <dak@gnu.org> writes:
>>Neon Absentius <absent@sdf.lonestar.org> writes:
>>> Is there a way to use the command replace-regexp to replace a number with
>>> that number increased, say, by 15? I tried
>>>
>>> C-M-% -?[0-9]+ RET (number-to-string (+ (string-to-number "\&") 15)) RET
>>>
>>> but it doesn't work because emacs interprets the second input to be
>>> a string and so it doesn't evaluate it. So I guess the question is
>>> how can we use the result of evaluating a sexp for replacement text?
>>>
>>> Any help and/or pointers to documentation will be greatly
>>> appreciated.
>>
>> The development version of Emacs would offer
>> C-M-% -?[0-9]+ RET \,(+ \#& 15) RET
>
> Oh, heh! Very neat ;)
The example in the Emacs manual is more amusing in my opinion, but
then I am biased.
For computing replacement strings for `\,', the `format' function is
often useful (*note Formatting Strings: (elisp)Formatting Strings.).
For example, to add consecutively numbered strings like `ABC00042' to
columns 73 to 80 (unless they are already occupied), you can use
M-x replace-regexp <RET> ^.\{0,72\}$ <RET>
\,(format "%-72sABC%05d" \& \#) <RET>
--
David Kastrup, Kriemhildstr. 15, 44793 Bochum
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: replace-regexp question
2005-10-26 19:52 ` David Kastrup
@ 2005-10-27 9:01 ` Harald Hanche-Olsen
2005-10-27 9:32 ` David Kastrup
0 siblings, 1 reply; 12+ messages in thread
From: Harald Hanche-Olsen @ 2005-10-27 9:01 UTC (permalink / raw)
+ David Kastrup <dak@gnu.org>:
| The example in the Emacs manual is more amusing in my opinion, but
| then I am biased.
|
| For computing replacement strings for `\,', the `format' function is
| often useful (*note Formatting Strings: (elisp)Formatting Strings.).
| For example, to add consecutively numbered strings like `ABC00042' to
| columns 73 to 80 (unless they are already occupied), you can use
Cute, but only understandable by old geezers who remember punch cards.
Ahh, the days of Real programmers.
--
* Harald Hanche-Olsen <URL:http://www.math.ntnu.no/~hanche/>
- Debating gives most of us much more psychological satisfaction
than thinking does: but it deprives us of whatever chance there is
of getting closer to the truth. -- C.P. Snow
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: replace-regexp question
2005-10-27 9:01 ` Harald Hanche-Olsen
@ 2005-10-27 9:32 ` David Kastrup
0 siblings, 0 replies; 12+ messages in thread
From: David Kastrup @ 2005-10-27 9:32 UTC (permalink / raw)
Harald Hanche-Olsen <hanche@math.ntnu.no> writes:
> + David Kastrup <dak@gnu.org>:
>
> | The example in the Emacs manual is more amusing in my opinion, but
> | then I am biased.
> |
> | For computing replacement strings for `\,', the `format' function is
> | often useful (*note Formatting Strings: (elisp)Formatting Strings.).
> | For example, to add consecutively numbered strings like `ABC00042' to
> | columns 73 to 80 (unless they are already occupied), you can use
>
> Cute, but only understandable by old geezers who remember punch
> cards. Ahh, the days of Real programmers.
You are biased.
--
David Kastrup, Kriemhildstr. 15, 44793 Bochum
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: replace-regexp question
2005-10-26 17:34 ` replace-regexp question David Kastrup
2005-10-26 18:24 ` Giorgos Keramidas
@ 2005-10-27 11:47 ` Neon Absentius
2005-10-27 14:38 ` Sébastien Kirche
2 siblings, 0 replies; 12+ messages in thread
From: Neon Absentius @ 2005-10-27 11:47 UTC (permalink / raw)
On Wed, Oct 26, 2005 at 07:34:11PM +0200, David Kastrup wrote:
>
> The development version of Emacs would offer
> C-M-% -?[0-9]+ RET \,(+ \#& 15) RET
>
Great. Thanks.
--
There is no national science just as there is no national
multiplication table; what is national is no longer science.
-- Anton Checov
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: replace-regexp question
2005-10-26 17:34 ` replace-regexp question David Kastrup
2005-10-26 18:24 ` Giorgos Keramidas
2005-10-27 11:47 ` Neon Absentius
@ 2005-10-27 14:38 ` Sébastien Kirche
2005-10-27 15:08 ` David Kastrup
2 siblings, 1 reply; 12+ messages in thread
From: Sébastien Kirche @ 2005-10-27 14:38 UTC (permalink / raw)
At 19:10 on oct 26 2005, David Kastrup said :
> The development version of Emacs would offer
> C-M-% -?[0-9]+ RET \,(+ \#& 15) RET
Sounds great. But I did not found its reference in the manual in the
section "syntax of regular expressions".
Is it already documented ? If yes, could you give the section of manual ?
Thanks.
--
Sébastien Kirche
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: replace-regexp question
2005-10-27 14:38 ` Sébastien Kirche
@ 2005-10-27 15:08 ` David Kastrup
2005-10-27 17:24 ` Sébastien Kirche
0 siblings, 1 reply; 12+ messages in thread
From: David Kastrup @ 2005-10-27 15:08 UTC (permalink / raw)
Sébastien Kirche <sebastien.kirche.no@spam.free.fr.invalid> writes:
> At 19:10 on oct 26 2005, David Kastrup said :
>
>> The development version of Emacs would offer
>> C-M-% -?[0-9]+ RET \,(+ \#& 15) RET
>
> Sounds great. But I did not found its reference in the manual in the
> section "syntax of regular expressions".
>
> Is it already documented ? If yes, could you give the section of manual ?
(info "(emacs) Regexp replace")
And of course it is also documented when you do
C-h k C-M-%
--
David Kastrup, Kriemhildstr. 15, 44793 Bochum
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: replace-regexp question
2005-10-27 15:08 ` David Kastrup
@ 2005-10-27 17:24 ` Sébastien Kirche
0 siblings, 0 replies; 12+ messages in thread
From: Sébastien Kirche @ 2005-10-27 17:24 UTC (permalink / raw)
At 17:10 on oct 27 2005, David Kastrup said :
> (info "(emacs) Regexp replace")
>
> And of course it is also documented when you do
>
> C-h k C-M-%
Thanks.
--
Sébastien Kirche
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2005-10-27 17:24 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <mailman.12812.1130346970.20277.help-gnu-emacs@gnu.org>
2005-10-26 17:34 ` replace-regexp question David Kastrup
2005-10-26 18:24 ` Giorgos Keramidas
2005-10-26 19:52 ` David Kastrup
2005-10-27 9:01 ` Harald Hanche-Olsen
2005-10-27 9:32 ` David Kastrup
2005-10-27 11:47 ` Neon Absentius
2005-10-27 14:38 ` Sébastien Kirche
2005-10-27 15:08 ` David Kastrup
2005-10-27 17:24 ` Sébastien Kirche
2005-10-26 17:15 Neon Absentius
-- strict thread matches above, loose matches on Subject: below --
2003-06-02 11:21 Chang Luo
2003-06-02 11:53 ` lawrence mitchell
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).