From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: kamphausen@creativepharma.com (Stefan Kamphausen) Newsgroups: gmane.emacs.help Subject: Re: I can't believe: replace regexp in a string Date: 15 Feb 2003 07:07:36 -0800 Organization: http://groups.google.com/ Sender: help-gnu-emacs-bounces+gnu-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: <62ede926.0302150707.66866ad6@posting.google.com> References: <62ede926.0302140037.4db6c80a@posting.google.com> <5lheb6zwkj.fsf@rum.cs.yale.edu> NNTP-Posting-Host: main.gmane.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: main.gmane.org 1045321826 10740 80.91.224.249 (15 Feb 2003 15:10:26 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Sat, 15 Feb 2003 15:10:26 +0000 (UTC) Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 18k3xN-0002n1-00 for ; Sat, 15 Feb 2003 16:10:22 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 18k3xZ-0002im-00 for gnu-help-gnu-emacs@m.gmane.org; Sat, 15 Feb 2003 10:10:33 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!postnews1.google.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 43 Original-NNTP-Posting-Host: 80.134.92.165 Original-X-Trace: posting.google.com 1045321656 12535 127.0.0.1 (15 Feb 2003 15:07:36 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: 15 Feb 2003 15:07:36 GMT Original-Xref: shelby.stanford.edu gnu.emacs.help:110234 Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1b5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Help: List-Post: List-Subscribe: , List-Archive: List-Unsubscribe: , Errors-To: help-gnu-emacs-bounces+gnu-help-gnu-emacs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.help:6736 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:6736 Dear Stefan "Stefan Monnier " 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