[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: replace matches in any string
From: |
David Kastrup |
Subject: |
Re: replace matches in any string |
Date: |
Thu, 02 Sep 2010 18:45:32 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) |
Stefan Monnier <address@hidden> 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
- Re: replace matches in any string, Ted Zlatanov, 2010/09/01
- Re: replace matches in any string, Stefan Monnier, 2010/09/02
- Re: replace matches in any string, Ted Zlatanov, 2010/09/02
- Re: replace matches in any string, Lars Magne Ingebrigtsen, 2010/09/02
- Re: replace matches in any string, Stefan Monnier, 2010/09/02
- Re: replace matches in any string,
David Kastrup <=
- Re: replace matches in any string, Ted Zlatanov, 2010/09/02
- Re: replace matches in any string, David Kastrup, 2010/09/02
- Re: replace matches in any string, Ted Zlatanov, 2010/09/02
- Re: replace matches in any string, David Kastrup, 2010/09/02
- Re: replace matches in any string, Ted Zlatanov, 2010/09/02
- Recommended gnus spam filter system?, Camm Maguire, 2010/09/02
- Re: Recommended gnus spam filter system?, Frank Schmitt, 2010/09/02
- Re: Recommended gnus spam filter system?, Karl Fogel, 2010/09/02
- Re: Recommended gnus spam filter system?, Thorsten Bonow, 2010/09/03
- Re: replace matches in any string, Stefan Monnier, 2010/09/02