title: How can I regexp replace a string in an elisp function?
body: <p>I'm writing myself a little helper function and one of the things I would like to do in it is to do a replace based on regex. <code>replace-regexp-in-string</code> looked like a good candidate. I'm unable, however, to get it to replace with capture. Here are all the things I have tried based on the emacs wiki:</p>
  
  <pre><code>(replace-regexp-in-string "a(b)c" "d\0f" "abc")
  (replace-regexp-in-string "a(b)c" "d \0 f" "abc")
  (replace-regexp-in-string "a(b)c" "d\\0f" "abc")
  (replace-regexp-in-string "a(b)c" "d \\0 f" "abc")
  (replace-regexp-in-string "a(b)c" "d\1f" "abc")
  (replace-regexp-in-string "a(b)c" "d \1 f" "abc")
  (replace-regexp-in-string "a(b)c" "d\\1f" "abc")
  (replace-regexp-in-string "a(b)c" "d \\1 f" "abc")
  </code></pre>
  
  <p>All of the above seem to evaluate to "abc" which puzzles me greatly. For <code>d\0f</code>, I would expect the result to be "dbf". I'm starting to suspect that this function doesn't do captures.</p>
  
  <p>What is the correct way to do this? Alternatively, what's the way to do this in general? A lot of the functions that deal with replacing regexp only deal with whole buffers while I need to transform some text it place.</p>