[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Can't get replace-match to replace intended match-data
From: |
Ehud Karni |
Subject: |
Re: Can't get replace-match to replace intended match-data |
Date: |
Sun, 30 Sep 2001 15:07:51 +0200 |
On Sun, 30 Sep 2001 11:26:05 +0200 (MET DST), Jonas Jarnestrom
<erajonj@ki.ericsson.se> wrote:
>
> > >
> > > (defun cs-head-set-target ()
> > > ""
> > > (interactive)
> > > (goto-char (point-min))
> > > (and (re-search-forward "Target: +<\\(.*\\)>" 400 'noerr)
> > ^
> > change the . to [^>] here-----+
> > ^
> > no further than to next '>' as stated here---+
>
> > > (replace-match "perka" nil nil nil 1))
> > > )
> >
> > Regular expressions matches the MAXIMUM possible string. If your search
> > was not limited to 400 characters, Your expression would have taken
> > from the 1st "Target: <" up to the last ">" in your file.
> >
> Hi Ehud,
>
> Thanks a lot for your answer.
>
> However I must assert that your conclusions are wrong.
> It's true that the '*' is very greedy and devours as much as he can,
> but he cannot go further than to the next '>', that is defined in
> the search string. (See above) I have verified this very carefully.
>
> Your suggested [^>] I have already tried numerous times,
> and in this case it is 100% equivalent to the original '.*'
You are wrong. The `.' may not include New Line (\n) but it sure
include `>'. To check it change your Target line to something like:
# Target: <cpmerge_dir> xxx> yzf <gfhkfghds>
and your construct (.*) will take until the last `>', while my
suggestion ([^>]*) will take only the 1st `>'.
I looked again at your original message and it looks it is something
else, not the replace-match problem.
Check if your `re-search-forward' and `replace-match' are the built-in
ones. Also, try it on a new clean session without local modifications
(i.e. emacs -q).
Ehud.
--
Ehud Karni Mivtach - Simon Insurance /"\
Tel: +972-3-7966-561 Fax: +972-3-7966-667 \ / ASCII Ribbon Campaign
(USA) Fax and voice mail: 1-815-5509341 X Against HTML Mail
Better Safe Than Sorry / \
mailto:ehud@unix.simonwiesel.co.il http://www.simonwiesel.co.il