From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: David Kastrup Newsgroups: gmane.emacs.devel,gmane.emacs.gnus.general Subject: Re: replace matches in any string Date: Thu, 02 Sep 2010 18:45:32 +0200 Organization: Organization?!? Message-ID: <87zkw0ccwj.fsf@lola.goethe.zz> References: <87ab3gfb41.fsf@hati.baby-gnu.org> <87r5wrgg8w.fsf@lifelogs.com> <87y6gvwryp.fsf@hati.baby-gnu.org> <87d3y7p1ie.fsf@gnu.org> <87633y7v02.fsf@hati.baby-gnu.org> <87vdbyccgg.fsf@hati.baby-gnu.org> <87eiikdfub.fsf@hati.baby-gnu.org> <87ocf18ntz.fsf@hati.baby-gnu.org> <87aaq2uldu.fsf@lifelogs.com> <87y6dg5vv2.fsf@hati.baby-gnu.org> <878w4skgqn.fsf_-_@lifelogs.com> <87sk1tk1px.fsf@lifelogs.com> <87fwxs5m0h.fsf@lifelogs.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1283446475 9869 80.91.229.12 (2 Sep 2010 16:54:35 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 2 Sep 2010 16:54:35 +0000 (UTC) Cc: ding@gnus.org To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Sep 02 18:54:34 2010 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1OrD3Y-0001ZG-ES for ged-emacs-devel@m.gmane.org; Thu, 02 Sep 2010 18:54:32 +0200 Original-Received: from localhost ([127.0.0.1]:37550 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OrCvv-0006w0-4Y for ged-emacs-devel@m.gmane.org; Thu, 02 Sep 2010 12:46:39 -0400 Original-Received: from [140.186.70.92] (port=43925 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OrCvj-0006ho-Br for emacs-devel@gnu.org; Thu, 02 Sep 2010 12:46:33 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OrCv9-0007CO-W6 for emacs-devel@gnu.org; Thu, 02 Sep 2010 12:45:53 -0400 Original-Received: from lo.gmane.org ([80.91.229.12]:60884) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OrCv9-0007C8-LG for emacs-devel@gnu.org; Thu, 02 Sep 2010 12:45:51 -0400 Original-Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1OrCv6-00074n-86 for emacs-devel@gnu.org; Thu, 02 Sep 2010 18:45:48 +0200 Original-Received: from p508ecf4b.dip.t-dialin.net ([80.142.207.75]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 02 Sep 2010 18:45:48 +0200 Original-Received: from dak by p508ecf4b.dip.t-dialin.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 02 Sep 2010 18:45:48 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 35 Original-X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: p508ecf4b.dip.t-dialin.net X-Face: 2FEFf>]>q>2iw=B6, xrUubRI>pR&Ml9=ao@P@i)L:\urd*t9M~y1^:+Y]'C0~{mAl`oQuAl \!3KEIp?*w`|bL5qr,H)LFO6Q=qx~iH4DN; i"; /yuIsqbLLCh/!U#X[S~(5eZ41to5f%E@'ELIi$t^ Vc\LWP@J5p^rst0+('>Er0=^1{]M9!p?&:\z]|;&=NP3AhB!B_bi^]Pfkw User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) Cancel-Lock: sha1:/ybazR112M6yP14aePLFJGGitGQ= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:129606 gmane.emacs.gnus.general:70371 Archived-At: Stefan Monnier writes: > I think I'm beginning to understand. > First, you don't want > > (replace-match "[first greek letter \\1]" nil nil string 1) > but > (replace-match "[first greek letter \\1]" nil nil string) > > then second, you do get the behavior you want in the particular case > where the string-match matched the whole string. > So to simulate: > >> (let ((regex "\\(alpha\\)") >> (string "gamma alpha beta")) >> (when (string-match regex string) >> (our-new-function "found greek letter \\1"))) >> -> "found greek letter alpha" > > you'd want: > > (let ((regex "\\(alpha\\)") > (string "gamma alpha beta")) > (when (string-match (concat "\\`.*?\\(?:" regex "\\).*\\'") string) > (replace-match "found greek letter \\1" nil nil string))) You mean like (let ((regex "\\(alpha\\)") (string "gamma alpha beta")) (when (string-match regex string) (match-substitute-replacement "found greek letter \\1" nil nil string))) -- David Kastrup