From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Lars Magne Ingebrigtsen Newsgroups: gmane.emacs.gnus.general,gmane.emacs.devel Subject: Re: replace matches in any string Date: Thu, 02 Sep 2010 16:44:09 +0200 Organization: Programmerer Ingebrigtsen Message-ID: 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 X-Trace: dough.gmane.org 1283438720 5227 80.91.229.12 (2 Sep 2010 14:45:20 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 2 Sep 2010 14:45:20 +0000 (UTC) Cc: emacs-devel@gnu.org To: ding@gnus.org Original-X-From: ding-owner+M18752@lists.math.uh.edu Thu Sep 02 16:45:19 2010 Return-path: Envelope-to: ding-account@gmane.org Original-Received: from util0.math.uh.edu ([129.7.128.18]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1OrB2T-0001nu-Rq for ding-account@gmane.org; Thu, 02 Sep 2010 16:45:18 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.math.uh.edu) by util0.math.uh.edu with smtp (Exim 4.63) (envelope-from ) id 1OrB2M-00013i-DU; Thu, 02 Sep 2010 09:45:10 -0500 Original-Received: from mx2.math.uh.edu ([129.7.128.33]) by util0.math.uh.edu with esmtps (TLSv1:AES256-SHA:256) (Exim 4.63) (envelope-from ) id 1OrB2L-00013V-55 for ding@lists.math.uh.edu; Thu, 02 Sep 2010 09:45:09 -0500 Original-Received: from quimby.gnus.org ([80.91.231.51]) by mx2.math.uh.edu with esmtp (Exim 4.72) (envelope-from ) id 1OrB2G-00049s-TE for ding@lists.math.uh.edu; Thu, 02 Sep 2010 09:45:09 -0500 Original-Received: from lo.gmane.org ([80.91.229.12]) by quimby.gnus.org with esmtp (Exim 3.36 #1 (Debian)) id 1OrB2G-0006Bh-00 for ; Thu, 02 Sep 2010 16:45:04 +0200 Original-Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1OrB2G-0001em-5i for ding@gnus.org; Thu, 02 Sep 2010 16:45:04 +0200 Original-Received: from cm-84.215.34.171.getinternet.no ([84.215.34.171]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 02 Sep 2010 16:45:04 +0200 Original-Received: from larsi by cm-84.215.34.171.getinternet.no with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 02 Sep 2010 16:45:04 +0200 X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: ding@gnus.org Original-Lines: 40 Original-X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: cm-84.215.34.171.getinternet.no Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAFVBMVEXVrahOLi0XCgoRBQai WlJ4UU/GbmNPPSDUAAACb0lEQVQ4jV2TzXbjIAyFWTReFxyyR8SzN7xA0wOsQ8by2ulxeP9HmCs7 7clU/gnms650IVbM1eI0PpBLLDElCcXV22qrjyaG4yvQ1XAlH4OJY9WWp5xKawDOau4DhehjJD/g /TUty4oMrWugiDNG52gTW5RKSgqwCUYSDIYTQFGqobg29oYicfR+0FNmzmltDRlktOhIONTmqaQG MJgw5NsTBDvt7QL0o3Ga0FU4fsZ43JTSBBAJllEhjjb5aCu0yg6CJvsXKuZ4MV471pyaSIXg3GTI kz9/BR/Gi648w7ty3jljKF2i+/Te0NGQPa+lKe2Dxvh0gz/XB8d5oKGckqo3o+1qTihD5x7VNeyX mhRei/HsyicRDT6y8Y5syZOKzkSaLwXzkfr4gFcaZunK9HG8cLkJqbY1E8LA4kOC3J87gCa0w+Sw LOJc1ojmley0Fv4OcS7g2NoFwg/ZclxZMkDG9mhbCEhZtgoG49hb5rmtOJoMhKI4lkZjNJc16fIK bK0AMLvy2BpkZp6m1BZV5Z+ICy8OACWDQXNRvCkhOXOmeeZVyguYvhvP05d30tHcNmDzE6wN6wgb H62VDXxntEclOjWeO3H0CoD0SczsYHgBiPT8VWq4qoOs0HNi/sm44thaae1e2mN6pGcG4oCcDTgt +5/r1hWClwOvS7ujXU9ksz6WTUqt1zdeVWdoAwiH7VHI6T7Um9oBhSD3QYpc8VmpDMU7bZNbJIB3 KdNJD/ucj3Kf8fyh9jiQ9z8pDhMaX+mh65YDvYYSd1fBSf0C2EOIdW+X7F+kSP2Esb8yun1d1O19 9xf+y4DB29WEF6l/btUBDCbRZUgAAAAASUVORK5CYII= Mail-Copies-To: never X-Now-Playing: Nadja's _Skin Turns to Glass_: "Skin Turns to Glass" User-Agent: Gnus/5.110011 (No Gnus v0.11) Emacs/24.0.50 (gnu/linux) Cancel-Lock: sha1:nwFqbTPaziOT/yoXclX7n7zRvmc= X-Spam-Score: -1.9 (-) List-ID: Precedence: bulk Xref: news.gmane.org gmane.emacs.gnus.general:70368 gmane.emacs.devel:129598 Archived-At: Ted Zlatanov writes: > We want to do it with regex "\\(X\\)" against "userX@valid.domain" and > target group "something-\\1-other". Does that make sense? Basically we > want \1 but without the context of that original string we matched: > > (let ((regex "\\(alpha\\)") > (string "gamma alpha beta")) > (when (string-match regex string) > (our-new-function "found greek letter \\1"))) > -> "found greek letter alpha" If you look at the low-level stuff that's actually saved by `string-match' and friends, it's basically a list of start/end points, and that's it, I think. (progn (string-match "\\(alpha\\)" "gamma alpha beta") (match-data)) => (6 11 6 11) So when you say `(match-string 1)', it just uses the range 6-11 and does a buffer-substring on that, or, if you give the latter function a string parameter, then a substring on that. So, for reasons of efficiency (I'm guessing), the actual substrings that were matched aren't stored anywhere. Now, the simplest change here would be if `string-match' and friends also saved what it did the match on in addition to the current match data. Then things like (replace-match "letter \\1" nil nil t) would "remember" that we're referring to the string in question. The performance impact should be minimal -- just an extra `setq' on a global C variable that would refer to the string we matched. -- (domestic pets only, the antidote for overdose, milk.) larsi@gnus.org * Lars Magne Ingebrigtsen