[Top][All Lists]

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

Re: replace matches in any string

From: Ted Zlatanov
Subject: Re: replace matches in any string
Date: Thu, 02 Sep 2010 12:51:07 -0500
User-agent: Gnus/5.110011 (No Gnus v0.11) Emacs/24.0.50 (gnu/linux)

On Thu, 02 Sep 2010 19:22:35 +0200 David Kastrup <address@hidden> wrote: 

DK> Ted Zlatanov <address@hidden> writes:
>> That would be great.  Then we wouldn't have to play the string-match
>> regex escaping game above.  But it complicates the code a bit to
>> provide `string'.

DK> Hardly.

Is "a tiny bit" more accurate?  In any case,
`match-substitute-replacement' seems like the right function.  Thank

>> I think Lars's suggestion to always save `string' to the same global
>> variable is sensible;

DK> For one thing I guess it is too late to change the API.

There's no change!  Saving the string is setting just one pointer
reference and does not change any existing code or APIs.

DK> For another, that prevents strings from being garbage-collected as
DK> long as they are present in some match-data.  While the same is true
DK> of buffers, a dead buffer does not take significant space.

Only one string would be kept around, not all the matches (I think
you're thinking of the tacked-on wishlist item below).

>> In general, it would be really nice if there was a
>> match-string/string-match/replace-match API variation that worked like
>> Perl's $1...$9 and Perl's named captures.  Those simply contain the
>> matched substring.

DK> What's wrong with match-substitute-replacement ?

It works for numeric capture offsets, thank you.  Named captures,
however, make regular expressions much easier to read and reuse.  Emacs,
being 25% regular expressions, would surely benefit from this.

We already have the `\(?NUM: ... \)' construct to explicitly set the
offset, so named captures could be as simple as `\(?'name': ... \)' or
some similar syntax.


reply via email to

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