GNU bug report logs -
#12622
replace-regexp-in-string
Previous Next
Full log
View this message in rfc822 format
Am 11.10.2012 16:44, schrieb Andreas Schwab:
> Andreas Röhler <andreas.roehler <at> easy-emacs.de> writes:
>
>> Also would expect a respective form working with replace-regexp-in-string
>>
>> (setq mystring "[.A foobar] [.B baz]")
>> (replace-regexp-in-string "\\_<\\w+\\_>" (concat "\\\\" (match-string-no-properties 0) ) mystring)
>>
>> but it fails.
>
> Fails in which way? What do you expect, and what do you get?
>
>> When commenting "(match-string 0 str)" as follows it subr.el it works
>>
>> (setq matches
>> (cons (replace-match (if (stringp rep)
>> rep
>> (funcall rep
>> ;; (match-string 0 str)
>> ))
>> fixedcase literal str subexp)
>>
>> Which has some plausibility: when receiving a user-specified function, there must not be that argument.
>
> Why? That's what the doc string documents.
>
> Andreas.
>
(setq mystring "[.A foobar] [.B baz]")
;; works nice in buffer
(while (re-search-forward "\\_<\\w+\\_>" nil t 1)
(replace-match (concat "\\\\\\\\" (match-string-no-properties 0) )))
==>
[.A \\foobar] [.B \\baz]
has unpredictable results
(setq mystring "[.A foobar] [.B baz]")
(replace-regexp-in-string "\\_<\\w+\\_>" (concat "\\\\" (match-string-no-properties 0)) mystring) ==>
"[.A \\ext in that fi] [.B \\ext in that fi]"
for example,
Docstring says:
"If it is a function, it is called with the actual text of each
match, and its value is used as the replacement text."
Which is not the case AFAIS.
This bug report was last modified 12 years and 225 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.