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]
it should also work with
[.A' foobar] [.B -baz]
=>
[.A'\\foobar] [.B\\-baz]
From jlf @ #emacs
(while (string-match "\(.*\w\) \(\w\)" str)
(setq str (concat (match-string 1 str) "\\" (match-string 2 str))))
(replace-regexp-in-string ” \\_<\\w+\\_>” (lambda (x) (concat “\\\\s” (substring x 1))) mystring)