GNU bug report logs -
#12622
replace-regexp-in-string
Previous Next
Full log
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
Hi,
the following question was raised at:
http://stackoverflow.com/questions/12809610/replace-regexp-in-string-with-lookahead-behind
I'd like to replace all occurrences of \w \w with \w\\\w in a string, where the \w parts stay the same before and after the replacement, e.g.
[.A foobar] [.B baz]
should result in
[.A\\foobar] [.B\\baz]
;;;;;;;;;;
this might be solved in buffer
by
(while (re-search-forward "\\_<\\w+\\_>" nil t 1)
(replace-match (concat "\\\\\\\\" (match-string-no-properties 0) )))
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.
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.
Maybe have a look,
Best,
Andreas
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.