help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: I can't believe: replace regexp in a string


From: Stefan Kamphausen
Subject: Re: I can't believe: replace regexp in a string
Date: 15 Feb 2003 07:07:36 -0800

Dear Stefan

"Stefan Monnier <foo@acm.com>" <monnier+gnu.emacs.help/news/@flint.cs.yale.edu> 
wrote in message news:<5lheb6zwkj.fsf@rum.cs.yale.edu>...
> > somehow I can't believe it. When I try to replace a regexp in a string
> > I have to create a temporary buffer and use the usual buffer
> > replacement commands or write a loop over the sequence. Is that true?
> > I have found a posting in this group describing that and have looked
> > at the XEmacs sources of subr.el where a defun replace-in-string is
> > defined which does one of the above procedures depending on the length
> > of the string. Having coded in Perl a good deal this seems quite
> > strange to me, but if it is the elispish way to do it, I'll give in
> 
> I'm not sure what's your complaint exactly.
> Is it that XEmacs' replace-in-string is not standard in Emacs (this
> is addressed in Emacs-21 with replace-regexp-in-string) or is it
> that you find both implementations of replace-in-string inefficient
> (how is it implemented in Perl) ?

I'm just wondering that such a trivial task (if your used to "$string
=~ s/match-re/replace-re/" in Perl) like doing a match and replace on
a string seems to be really non-trivial in Emacs, and I'm speaking of
both Emacsen here. I thought I must have missed something somewhere.
 
> Finally, the reason why it took so long for Emacs to provide
> replace-regexp-in-string is because Emacs uses buffers a lot more than
> strings, so if you need replace-regexp-in-string it's maybe because you
> made the arguably wrong decision to use a string rather than a buffer.

Hm, I'm parsing a text file and need to replace some trailing
whitespaces from a substring I just read. You're right in that I could
do that replacement in the buffer I use for reading the files'
contents (and thinking about that right now I might just do it that
way ;-). Thanks for that hint.

> Perl is great with strings, Emacs is great with buffers.

:-)

And thanks to all the other posters! I will be able to find a solution
with all those hints :-)

Thanks and Regards
Stefan Kamphausen


reply via email to

[Prev in Thread] Current Thread [Next in Thread]